VB Tutorial
Tools
Free Downloads
Free Link Directory

Basics
Data Types
Windows Forms
Buttons
Check Box
Text Box
Combo Box
Radio Buttons
Progress Bar
Color & Font Dialogs
Open & Save Dialogs
Process Control

More Complex Examples
Audio Player
Rotating Rectangle

 

Link progress bar with timer in vb.net

Basic Controls with Visual Basic 2008

The primary use of a ProgressBar is to show process progress. The ProgressBar's Style attribute can be set to either Blocks, Continuous or Marquee. We will build a small example to demonstrate how they work. Start by creating a new project. From the Toolbox menu create the following controls on the form:
ProgressBar1
ProgressBar2
Label1
Timer1

Now space the controls on the form as in the example Figure 8.


Figure 8: ProgressBar

Lets change the necessary attributes in the forms Load handling event instead of going to each individual attribute list. Double click on the form to change its load event and on Timer1 to change its tick event. We are going to link the progress bar with the timer event in vb.net. The end result in the Code View should look like the following.

Public Class Form1
Dim MyProgress As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ProgressBar1.Style = ProgressBarStyle.Marquee
ProgressBar2.Style = ProgressBarStyle.Continuous
ProgressBar2.Step = 1
Timer1.Enabled = True
End Sub


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar2.Value = MyProgress
If MyProgress < 100 Then MyProgress = MyProgress + 1
Label1.Text = "File Upload = " & MyProgress & "%"
If MyProgress = 100 Then
    Label1.Text = "Complete"
    ProgressBar1.Visible = False
End If

End Sub
End Class

When u set a ProgressBar's Style to Marquee it will run continuously. The Timer event is set to occur every 100 milliseconds, which is configured in the Interval attribute. One second = a Value of 1000. In the forms load event we set ProgressBar2's .Step value to one. I determines the amount of increase that will occur at a time. The Integer called MyProgress increases itself with one every time Timer1 ticks. The label will add "%" to MyProgress in order to read, "File Upload = ?%". When MyProgress's value reaches 100 the label will change to "Complete" and ProgressBar1 will disappear.
If you liked this article then Please Thumb This Up with a short review - Stumble It!
Continue to the next page.


Email us at: info@pro2visual.com
 

Get your Website Listed on our Free Link Banner Directory
Advertise your site with your own unique link banner we will also provide text links to your site.

Popular Articles

Moving a borderless form in vb.net

ComboBox1.Items.Add

Link Progress Bar with Timer in vb.net

How to open a folder using the process control

Start Vb.net programming. No get rich quick scam

How to Convert the Date Format

Click here for Industry Leading Development Softwa