Visual Basic Progress Bar control provides the coolest way to show the progress of any background activity. It is good idea to show the progress to the end user when an application is performing complex or time consuming background tasks. Follow steps below to begin with:
- Drag and drop a progress bar control ProgressBar1 and button Button1 on the Form Design
- Dock the ProgressBar1 on the bottom side
- Go to ProgressBar1 properties and modify Step property value to 15
- Open code for Button1_Click event handling sub and paste following code in it
- Run the application using F5. Now whenever you press the Button1, the progress bar value is incremented to 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
Properties for Visual Basic Progress Bar Control
Style provides three display options for visual appearance
Blocks: The progress bar is shown in block increments. This option is not usable in modern windows
Continuous: The progress bar is shown as a continuous bar. This is the most common value of Style property
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
This property provides the value of the incremental step when PerfromStep() method is called.
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
ProgressBar1.Value = increment
- 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.