Name of the progress bar displayed: processbar
Main form: form1
Function: to perform a heavy workload on form1, a progress bar is displayed in the form.
Implementation Method:
Processbar form:
In the processbar form, set formborderstyle to none and startposition to centerscreen.
Place a progressbar1 control in the center of the form
Set maximun = 20, step = 1 for the progressbar1 Control
Add:
Public void addone ()
{
If (progressbar1.value = 20)
Progressbar1.value = 0;
Progressbar1.value ++;
}
Form1 form:
In namespace, the proxy is declared before the form1 class:
Public Delegate void addprocess ();
Declare an event in the form1 class
Public event addprocess doadd;
Then add the method:
// Very large work to do
Public void dowork ()
{
String sor = "";
For (INT I = 0; I <20000; I ++)
{
Sor + = I. tostring ();
If (I % 1000 = 0)
Doadd ();
}
// MessageBox. Show (SOR );
}
To trigger a heavy workload event, write as follows:
// Button: execute a large workload string connection
Private void button10_click (Object sender, system. eventargs E)
{
Procw.ar PJ = new procw.ar ();
This. doadd + = new addprocess (PJ. addone );
PJ. Show ();
Thread Mm = new thread (New threadstart (dowork ));
Mm. Start ();
Mm. Join ();
PJ. Close ();
}