BackColor and BarColor of a ProgressBar

BackColor and BarColor of a ProgressBar

It is not possible to modify the color of the bars and backcolor of a Progressbar directly by properties of control.

The only way to do that is to pass by an API call.
To run this code, you need a form and a progressbar named Progressbar1.

‘*********************************************
'Paste this code in a module or in the general section of a form
‘API DECLARATION
Public Declare Function SendMessage Lib _
  "user32" Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long

‘CONSTANT DECLARATION
Public Const CCM_FIRST = &H2000
Public Const CCM_SETBKCOLOR = (CCM_FIRST + 1)
Public Const PBM_SETBKCOLOR = CCM_SETBKCOLOR
Public Const WM_USER = &H400
Public Const PBM_SETBARCOLOR = (WM_USER + 9)
‘*********************************************

‘*********************************************
'Paste this code in a form

Private Sub Form_Load()

‘Set the ProgressBar Barcolor with black color
SendMessage ProgressBar1.hwnd, PBM_SETBARCOLOR, 0, ByVal RGB(0, 0, 0)

‘Set the ProgressBar Backcolor with blue color
SendMessage ProgressBar1.hwnd, PBM_SETBKCOLOR, 0, ByVal RGB(0, 0, 127)

End Sub

You might also like...

Comments

 WonderGuy

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“God could create the world in six days because he didn't have to make it compatible with the previous version.”