Changing Progress Bar Colors In VB.NET

this is a cool effect not a effect actually but like a effect so i made 3 colors for progressbar and actually they all looks awesome , they are red,green,yellow so lets get started

now if your on a project just add a progressbar or if your not on a project just create a new project and name it whatever you want and add a progressbar and double click your form and add these code below

Public Class Form1
    'ultimate programming tutorials
    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
    Enum ProgressBarColor
        Green = &H1
        Red = &H2
        Yellow = &H3
    End Enum
    Private Shared Sub ChangeProgBarColor(ByVal ProgressBar_Name As Windows.Forms.ProgressBar, ByVal ProgressBar_Color As ProgressBarColor)
        SendMessage(ProgressBar_Name.Handle, &H410, ProgressBar_Color, 0)
    End Sub
End Class

now if you want to make your progressbar color green , add this code to a click event a button is better



ChangeProgBarColor(ProgressBar1, ProgressBarColor.Green)

for yellow
Ultimate programming tutorials - progress bar color - yellow

ChangeProgBarColor(ProgressBar1, ProgressBarColor.Yellow)

for red
Ultimate programming tutorials - progress bar color - red

ChangeProgBarColor(ProgressBar1, ProgressBarColor.Red)

heres a video of how they are



if you want the full source code of my application i made for that video , here

Public Class Form1

    'Author : Mohamed Shimran
    'Blog : http://www.ultimateprogrammingtutorials.blogspot.com

    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
    Enum ProgressBarColor
        Green = &H1
        Red = &H2
        Yellow = &H3
    End Enum
    Private Shared Sub ChangeProgBarColor(ByVal ProgressBar_Name As Windows.Forms.ProgressBar, ByVal ProgressBar_Color As ProgressBarColor)
        SendMessage(ProgressBar_Name.Handle, &H410, ProgressBar_Color, 0)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ChangeProgBarColor(ProgressBar1, ProgressBarColor.Red)
        Timer1.Start()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ProgressBar1.Value = 0
        ChangeProgBarColor(ProgressBar1, ProgressBarColor.Green)
        Timer1.Start()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ProgressBar1.Value = 0
        ChangeProgBarColor(ProgressBar1, ProgressBarColor.Yellow)
        Timer1.Start()
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Value += 1
        If ProgressBar1.Value = 99 Then
            Timer1.Stop()
        End If
    End Sub
End Class

13 comments

Helped a lot for a temperature progress bar I was working on. Thanks a lot for this tutorial.

Reply

You are excellent. But can you help me on blue progrees bar, black progress bar ??

Reply

thank you :) what i have used here is the system styles that progressbar has ; you can do what you wanted with GDI i am sorry i don't do GDI :(

Reply

THANKS !!!!

Reply

What should we do if we want to have a CUSTOM color in our progressbar?

Reply

If you want custom colors then you have to make a custom progressbar using GDI

Reply

not too important, but ... thanks

Reply

After making progress bar "RED" it's not working, for example my program hanging at this line "ProgressBar1.Value = 0" in red progress bar.
But in Green, It's working normal.

Reply

My program is doing the same thing Please Help!

Reply

How to change to another color like blue and orange?

Reply

Yo this is lovely

Reply

Post a Comment

Note: Only a member of this blog may post a comment.