- This topic helps to display progress bar percentage in VB programming. In your Progress Bar control, the percentage will display in it.
- Tools needed: Button1 (Button1), ProgressBar1 (ProgressBar1)
ProgressBar Class – Display Progress Bar Percentage in VB
- ProgressBar Class represents a Windows progress bar control.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Syntax for progressBar Class
|
1 2 3 4 5 6 |
'Declaration <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ <DefaultBindingPropertyAttribute("Value")> _ <ComVisibleAttribute(True)> _ Public Class ProgressBar _ Inherits Control |
Control.CreateGraphics Method – Display Progress Bar Percentage in VB
- Control.CreateGraphics Method creates the Graphics for the control.
- Syntax for Control.CreateGraphics Method
|
1 2 |
'Declaration Public Function CreateGraphics As Graphics |
ProgressBar.Value Property – Display Progress Bar Percentage in VB
- It defines the current position of the progress bar.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Syntax for ProgressBar.Value
|
1 2 3 |
'Declaration <BindableAttribute(True)> _ Public Property Value As Integer |
ProgressBar.Maximum property – Display Progress Bar Percentage in VB
- It helps to set the maximum value of the range of the control.
- Syntax for ProgressBar.maximum
|
1 2 |
'Declaration Public Property Maximum As Integer |
Graphics.DrawString Method – Display Progress Bar Percentage in VB
- Draw the specified text string at the specified location with the specified Brush and Font objects.
Graphics.DrawString Method (String, Font, Brush, PointF) – Display Progress Bar Percentage in VB
- Draw the specified text string at the specified location with the specified Brush and Font objects.
- Parameters
String – String to Draw
Font – Font object that defines the text format of the string.
Brush – Brush object that determines the color and texture of the drawn text.
PointF – PointF structure that specifies the upper-left corner of the drawn text.
Display Progress Bar Percentage in VB – Complete Code
|
1 2 3 4 5 6 7 8 9 10 |
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ProgressBar1.Value = 0 ProgressBar1.Maximum = 100 ProgressBar1.Value = 60 Dim percent As New Integer percent = Convert.ToInt32(Convert.ToDouble(ProgressBar1.Value) / Convert.ToDouble(ProgressBar1.Maximum) * 100) ProgressBar1.CreateGraphics().DrawString(percent.ToString() + "%", New Font("Arial", 8.25, FontStyle.Regular), Brushes.Black, New PointF(ProgressBar1.Width / 2 - 10, ProgressBar1.Height / 2 - 7)) End Sub |
Display Progress Bar Percentage in VB
If you have any suggestions regarding this topic, please contact us…






