Click here to Skip to main content
15,885,244 members
Articles / Programming Languages / Visual Basic

Visual Basic Progress Bar control

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
17 Mar 2014CPOL2 min read 141.1K   2   1
Visual Basic Progress Bar control

Visual Basic Progress Bar control provides the coolest way to show the progress of any background activity. It is a good idea to show the progress to the end user when an application is performing complex or time consuming background tasks. Follow the steps given below to begin with:

  1. Drag and drop a progress bar control ProgressBar1 and button Button1 on the Form Design.
  2. Dock the ProgressBar1 on the bottom side.

    Visual Basic Progress Bar

  3. Go to ProgressBar1 properties and modify Step property value to 15.

    Visual Basic Progress Bar

  4. Open code for Button1_Click event handling sub and paste the following code in it:
    ProgressBar1.PerformStep()
  5. Run the application using F5. Now whenever you press the Button1, the progress bar value is incremented to the next step. We had updated the Step property to 15, so every step increases the progress bar by value of 15. Note that PerformStep() method does nothing when ProgressBar1 value is reached to the Maximum. The default value for Maximum is 100.

    Visual Basic Progress Bar

Properties for Visual Basic Progress Bar Control

Style

Style provides three display options for visual appearance:

  1. Blocks: The progress bar is shown in block increments. This option is not usable in modern windows.
  2. Continuous: The progress bar is shown as a continuous bar. This is the most common value of Style property.
  3. Marquee: Sometimes, we are not sure about the exact progress of a background task. In such cases, we use the Marquee style which shows the progress bar as always moving.

Step

This property provides the value of the incremental step when PerfromStep() method is called.

MarqueeAnimationSpeed

You can control the speed of moving progress bar animation. Default value is 100. The smaller the value, the faster will be the animation speed.

Modifying Value of Visual Basic Progress Bar in Code

Modify the Windows Application code as below:

Public Class Form1
    Dim increment As Integer = 0

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                 Handles Button1.Click

        increment = increment + 10
        If increment > ProgressBar1.Maximum Then
            increment = ProgressBar1.Maximum
        End If
        ProgressBar1.Value = increment

    End Sub

End Class

Tips

  • This code increases the progress bar value by 10 every time Button1 is pressed.
  • Whenever we are modifying the code of progress bar value, we must check whether the assigned value is less than the Maximum. A runtime error or exception will be returned if we assign a value greater than Maximum. The code is self-explanatory for this purpose.
  • Please note that we have not used PerformStep() method in this code.
  • We don’t have to perform value checks while using PerformStep(). It makes the coding much easier. Just define the value of Step property for progress bar and PerformStep() will increase the value by that step. Simple is that!

The post Visual Basic Progress Bar control appeared first on Bubble Blog.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer http://bubbleblog.net/
Pakistan Pakistan
A Telecom Engineer, Visual Basic enthusiast and Android news follower. He is contributing to an online blog as content writer and administrator
You can visit him here: http://bubbleblog.net/

Comments and Discussions

 
Questionprogress bar control Pin
Keith Kungwara11-Nov-21 20:41
Keith Kungwara11-Nov-21 20:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.