Change ProgressBar Color in VB.NET

Usually, the color of the progressbar is green. Now, we will create a program that changes the progressbar color in vb.net. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add three ProgressBar named ProgressBar1, ProgressBar2, and ProgressBar3. Add also a timer named Timer1 to fill in the progressbar. You must design your interface like this: clock design 3. Then we will code for changing the color of our progressbars. We will declare an auto function named SendMessage that will access the user32.dll because the color customization is found there.
  1. Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Declare the colors using the enum property.
  1. Enum ProgressBarColor
  2. Green = &H1
  3. Red = &H2
  4. Yellow = &H3
  5.  
  6. End Enum
Now, we will create a sub procedure named ChangeProgBarColor so that we can now change the color of the progressbars.
  1. Private Shared Sub ChangeProgBarColor(ByVal ProgressBar_Name As Windows.Forms.ProgressBar, ByVal ProgressBar_Color As ProgressBarColor)
  2. SendMessage(ProgressBar_Name.Handle, &H410, ProgressBar_Color, 0)
  3. End Sub
Code for the Timer1_Tick to process the progressbar and increments its value.
  1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  2. ProgressBar1.Value += 1
  3. ProgressBar2.Value += 1
  4. ProgressBar3.Value += 1
  5. If ProgressBar1.Value = 99 And ProgressBar2.Value = 99 And ProgressBar3.Value = 99 Then
  6. Timer1.Stop()
  7. End If
  8. End Sub
Lastly, in the Form_Load, call the sub procedure ChangeProgBarColor to color the progressbars and start the time.
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. ChangeProgBarColor(ProgressBar1, ProgressBarColor.Red)
  3. ChangeProgBarColor(ProgressBar2, ProgressBarColor.Yellow)
  4. ChangeProgBarColor(ProgressBar3, ProgressBarColor.Green)
  5. Timer1.Enabled = True
  6. End Sub

Output:

output For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment