A simple example of a progress bar is actually not your own thing. Just keep a Learning Record.
Using system. Windows. forms;
// Add reference in step 1
Using system. Threading;
Using system. IO;
Namespace progressbar
{
Public partial class form1: From
{
Public form1 ()
{
Initializecomponent ();
}
// Step 2 defines the value of the delegate update progress bar
Private delegate void setpos (int ipos );
// Update the progress bar value in step 3
Private void settextmessage (int ipos)
{
If (this. invokerequired)
{
Setpos = new setpos (settextmessage );
// This. Invoke is used when the main thread is modified outside the main thread
This. Invoke (setpos, new object [] {IPOs });
}
Else
{
This. label1.text = IPOs. tostring () + @ "/100 ";
This. pgb. value = convert. toint32 (IPOs );
}
}
// Use progress bars and develop functions
Private void button#click (Object sender, eventargs E)
{
Thread fthread = new thread (New threadstart (sleept ));
// Open up a new thread
Fthread. Start ();
}
// Prompt message
Public Delegate void showmsg (string MSG );
Public void msgbox (string MSG)
{
If (this. invokerequired)
{
Showmsg show_msg = new showmsg (msgbox );
This. Invoke (show_msg, new object [] {MSG });
}
Else
{
MessageBox. Show (MSG );
}
}
Private void sleept ()
{
For (INT I = 0; I <200; I ++)
{
// Simple latency
Thread. Sleep (100 );
Settextmessage (100 * I/200 );
}
Settextmessage (100 );
Msgbox ("success ");
}
}
}