Progress Bar Demo in Visual Basic .Net

This tutorial will demonstrate how to use and how progress bar in works.

What is a progress bar?

progress bar is a graphical control element used to visualize the progression of an extended computer operation, such as a download, file transfer, or installation.

Let’s start the tutorial

  1. Open your Microsoft Visual Studio 2010
  2. On the File menu select New Project
  3. Select Visual Basic then Windows Form Application. Click OK.
  4. We need to add the following controls to our form.
    1. 2 labels
    2. 1 timer
    3. And of course the progress bar control
  5. See the layout of the form below. (you are free to design and layout your form)


Note: Name the Label1 as lblload and Label2 as lblpercent.

  1. Double click Timer1 and paste the code.
ProgressBar1.Value = ProgressBar1.Value + 1
lblpercent.Text = ProgressBar1.Value / ProgressBar1.Maximum * 100 & " %"
If ProgressBar1.Value > 1 And ProgressBar1.Value < 30 Then
lblload.Text = "Loading program..."
If ProgressBar1.Value > 30 And ProgressBar1.Value < 60 Then
lblload.Text = "Loading components..."
If ProgressBar1.Value > 60 And ProgressBar1.Value < 100 Then
lblload.Text = "Loading database...please wait"
End If
End If
If ProgressBar1.Value = ProgressBar1.Maximum Then
Exit Sub
End If
End If

Code Explanation:

The code above will increment the value of our progress bar by 1. As the progress bar increases, Label2 or the lblpercent will display its progress in percent. Label1 or the lblload will display a text of “Loading program…” if the value of the progress bar is ranging from 1 to 30, “Loading components…” if progress bar is 30 to 60 and “Loading database… please wait” if value is 60 up to 100. The progress bar will stop if it reaches 100 and a message box will appear displaying “Welcome”.

Note: make sure the code is placed between the lines of:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

End Sub
  1. Lastly on the Load event of the form (just double the form) place the code.

It will automatically start the loading of progress bar.

  1. Save and Run the project.

Happy Coding! More tutorials to come (C#, Java, C++ and many more)



Post navigation