In this article we will how to use progress bar
control in a windows forms application using Visual Studio 2010.
Progress Bar control:
progress bar displays a bar that fills to
indicates to the user the progress of an operations, or Progress Bar
Control is used to display the progress of a task in Visual Basic. Mostly the
progress bar is used while accessing the databases, or downloading or copying
files from the network resources.
Property of progressbar control.
Maximum
This property is used to get or set the
progress bars maximum value.
Minimum
This property is used to get or set the
progress bars minimum value.
Value
This property is used to get or set the current
value of the progress bar.
Increment
This property is used to increase the position
of the progress bar by the given value.
PerformStep
This property is used to increment the value of
the progress bar by the Steps property.
Now taking a progress bar control, one button
named start time and a timer control on the form.
figure 1.
now double click on the button named start time
and add the following code on the button event.
VB code.
Private Sub Button1_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs)
Handles Button1.Click
timer1.Enabled = True
End Sub
C# code.
private void button1_Click(object
sender, EventArgs e)
{
timer1.Enabled = true;
}
now the timer tick event the progress bar value
is increased till its maximum in a loop and add the following code with the
timer tick event.
Now run the application press ctrl+F5 and click
on the button start time.
VB code.
Private Sub timer1_Tick(ByVal
sender As Object,
ByVal e As EventArgs)
progressBar1.Value += 1
If progressBar1.Value >= progressBar1.Maximum
Then
Timer1.Enabled = False
End If
End Sub
C# code.
private void timer1_Tick(object
sender, EventArgs e)
{
progressBar1.Value+=1;
if (progressBar1.Value >=
progressBar1.Maximum)
{
timer1.Enabled = false;
}
The progress bar looks
like this.

figure 2.