C # How to Implement the dual progress bar function in winform,
The progress bar prompts the user (we) about the status of the software being installed-percentage. When the installation software is too large, a progress bar prompt will appear very slow, then we can use two progress bars prompt. Displays the current progress and the overall progress. So how can this function be implemented? I would like to introduce the basic methods here and hope to help programmers and learn from them.
Open Microsoft Visual Studio 2010:
1. Create a solution
2. Add a new form-progress bar exercise
Form Layout
(1) Controls
There are 6 lable labels, 2 Progress bars, 1 button control, and 2 textbox Control;
(2) Basic Attributes
Lable label: Lbl_1; lbl_2; lbl_3; lbl_4; lbl_5; lbl_6;
Text: % overall progress of the current progress
Lbl_7 (used by the author to show examples)
Progressbar control: Pgb_1; pgb_2
Button Control: Text: installation!
TextBox Control: Txtb_1; txtb_2
Progress bar 1 Property settings
# Maximum: 500
Minimum: 1
Value: 1
Progress bar 2 Property settings
# Maximum: 100
Minimum: 1
Value: 1
Button Control click Event code
Progress bar 1 -- accumulate 500 times in a loop
(Note: add the "Application. DoEvents ();" statement)
Button Control click Event code
Progress bar 2 -- accumulate 100 times in a loop
(Note: add the "Application. DoEvents ();" statement)
Complete code
Namespace Design
{
Public partial class form2: Form
{
Public form2 ()
{
InitializeComponent ();
}
Private void btn_count_Click (object sender, EventArgs e)
{
For (int k = 1; k <= 100; k ++)
{
// Current progress
For (int I = 1; I <= 500; I ++)
{
Txtb_show_1.Text = I. ToString ();
Application. DoEvents ();
This. pgb_1.Value = I;
This. lbl_1.Text = (I/5). ToString ();
}
// Overall progress
Txtb_show_2.Text = k. ToString ();
Application. DoEvents ();
This. pgb_2.Value = k;
This. lbl_3.Text = k. ToString ();
}
}
}
}