0% found this document useful (0 votes)
40 views

L15-C2 Progress Bar Control

The document discusses the Windows progress bar control, which provides visual feedback about the status of a task. It displays a bar that fills from left to right as the operation progresses. Three examples are given of creating and updating progress bars at runtime using Visual Basic code. The code demonstrates how to set properties like minimum, maximum, and current values of the progress bar. It also shows how to increment the bar continuously using a timer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

L15-C2 Progress Bar Control

The document discusses the Windows progress bar control, which provides visual feedback about the status of a task. It displays a bar that fills from left to right as the operation progresses. Three examples are given of creating and updating progress bars at runtime using Visual Basic code. The code demonstrates how to set properties like minimum, maximum, and current values of the progress bar. It also shows how to increment the bar continuously using a timer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

L15-C2

Progress bar control


It represents a Windows progress bar control. It is used to provide visual
feedback to your users about the status of some task. It shows a bar that fills
in from left to right as the operation progresses.
Let's click on a ProgressBar control from the Toolbox and place it on the
form.

The main properties of a progress bar are Value, Maximum and Minimum.
The Minimum and Maximum properties are used to set the minimum and
maximum values that the progress bar can display. The Value property
specifies the current position of the progress bar.
The ProgressBar control is typically used when an application performs tasks
such as copying files or printing documents. To a user the application might
look unresponsive if there is no visual cue. In such cases, using the
ProgressBar allows the programmer to provide a visual status of progress.

Example1:
create a progress bar at runtime. Let's double click on the Form and
put the follow code in the opened window.
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) _


Handles MyBase.Load

'create two progress bars

Dim ProgressBar1 As ProgressBar

Dim ProgressBar2 As ProgressBar

ProgressBar1 = New ProgressBar()

ProgressBar2 = New ProgressBar()

'set position

ProgressBar1.Location = New Point(10, 10)

ProgressBar2.Location = New Point(10, 50)

'set values

ProgressBar1.Minimum = 0

ProgressBar1.Maximum = 200

ProgressBar1.Value = 130

ProgressBar2.Minimum = 0

ProgressBar2.Maximum = 100

ProgressBar2.Value = 40
'add the progress bar to the form

Me.Controls.Add(ProgressBar1)

Me.Controls.Add(ProgressBar2)

' Set the caption bar text of the form.

Me.Text = "tutorialspoint.com"

End Sub

End Class

When the above code is executed and run using Start button
available at the Microsoft Visual Studio tool bar, it will show the
following window:
Expermint2:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim x As Integer = 0
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 100
For x = 0 To 100
ProgressBar1.Value = x
Label1.Text = x

Next

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
ProgressBar2.Value = ProgressBar2.Value + 20

End Sub
End Clas

Example 3:
Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs)


Handles Button1.Click
If ProgressBar1.Value + 10 > ProgressBar1.Maximum Then
ProgressBar1.Value = ProgressBar1.Maximum
Else
ProgressBar1.Value += 10
End If

Label_value.Text = ProgressBar1.Value

End Sub

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs)


Handles Button3.Click
ProgressBar1.Value = 0
Label_value.Text = ProgressBar1.Value
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs)


Handles Button2.Click
ProgressBar1.Maximum = TextBox1.Text
End Sub

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles


MyBase.Load
TextBox1.Text = ProgressBar1.Maximum
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs)
Handles Button4.Click
ProgressBar1.Increment(TextBox2.Text)
Label_value.Text = ProgressBar1.Value

End Sub

Private Sub Button5_Click(sender As System.Object, e As System.EventArgs)


Handles Button5.Click
ProgressBar1.Step = TextBox3.Text
End Sub

Private Sub Button6_Click(sender As System.Object, e As System.EventArgs)


Handles Button6.Click
ProgressBar1.PerformStep()
Label_value.Text = ProgressBar1.Value
End Sub

Private Sub Button7_Click(sender As System.Object, e As System.EventArgs)


Handles Button7.Click
Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs)


Handles Timer1.Tick
ProgressBar1.PerformStep()
If ProgressBar1.Value = ProgressBar1.Maximum Then
Timer1.Stop()
End If
End Sub
End Class

You might also like