简体   繁体   中英

Progress indicator in C# Winforms

I have created some basic applications using windows forms C#.

What I am trying to achieve is that I have some task taking place inside a function. While executing that task I need to display a message box (with no buttons) with the text "Configuring...". I also need to blink this text. How can I do that?

Do I need to have another form for this? After completing this task this form needs to be hidden or closed?

I have googled this but couldn't see an answer, may be because of my unclear question in google.

I would use a ProgresBar. Therefore you need to do your work in a background worker. An example what I mean you can find here:

https://stackoverflow.com/a/12127025/2243584

If you want to have some Text on the ProgressBar you need to create your custom ProgressBar. A complete sample is available here:

https://stackoverflow.com/a/3529945/2243584

If you really need a progress indicator you have to do as toATwork said, and do a Background worker However, it is not a really async task, so you might find it hard to make it work properly

If you finally don't care about the message, and just need to show the users that something is happening, you can always use:

// To start
Cursor cursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;

// To finish
Cursor.Current = Cursors.Default;

This will just put the mouse cursor in "loading", but it might work for you

You can use a label on your form and change its text in function Body.

{
//your function body
label.Text="Configuring";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM