Question Progress Bar Color

crystaluz

Well-known member
Joined
Feb 17, 2009
Messages
55
Programming Experience
Beginner
Hello... I am new to VS 2008..
It is possible to change the progress bar loading color (green) to other color?
How to change it?
Thank you..
 
Please post in the most appropriate forum for the topic, not just the first one you come to. Thread moved.

The colour of the ProgressBar is set by the system theme. There's no simple way to change it and, while there may be one, I'm not even aware of a complex way to change it. You may just have to create your own control.
 
You can use this to mimic a progress bar, just set the .value for the percentage. Not sure where I found it, most likely Code Project.
VB.NET:
Imports System.ComponentModel
Imports System.Windows.Forms.Design

Public Class LabelBar
    Inherits Label
    Private mVal As Integer = 0               ' Current value
    Private mbarColor As Color = Color.Navy    ' Color of bar
    Private mbarHeight As Integer = 0
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim g As Graphics = e.Graphics
        Dim percent As Decimal = mVal / 100
        Dim brush As SolidBrush = New SolidBrush(BarColor)
        Dim rect As Rectangle = e.ClipRectangle
        Dim height As Integer = mbarHeight
        rect.Width = rect.Width * percent
        If height = 0 Then height = rect.Height
        rect.Y = (rect.Height - height) / 2
        rect.Height = height
        ' Draw bar
        g.FillRectangle(brush, rect)
        MyBase.OnPaint(e)
    End Sub
    <DefaultValue(0)> _
    Public Property Value() As Integer
        Get
            Return mVal
        End Get
        Set(ByVal Value As Integer)
            ' Make sure that the value does not stray outside the valid range.
            Select Case Value
                Case Is < 0
                    mVal = 0
                Case Is > 100
                    mVal = 100
                Case Else
                    mVal = Value
            End Select
            ' Invalidate the control to get a repaint.
            Me.Invalidate()
        End Set
    End Property
    <DefaultValue(GetType(Color), "Navy")> _
    Public Property BarColor() As Color
        Get
            Return mbarColor
        End Get
        Set(ByVal Value As Color)
            mbarColor = Value
            ' Invalidate the control to get a repaint.
            Me.Invalidate()
        End Set
    End Property
    <DefaultValue(0)> _
    Public Property BarHeight() As Integer
        Get
            Return mbarHeight
        End Get
        Set(ByVal value As Integer)
            Select Case value
                Case Is > Me.Size.Height, Is < 0
                    mbarHeight = Me.Size.Height
                Case Else
                    mbarHeight = value
            End Select
            ' Invalidate the control to get a repaint.
            Me.Invalidate()
        End Set
    End Property
End Class
 
VB.NET:
brush.Dispose()
or
VB.NET:
Using brush As New SolidBrush(color)
...
End Using
 
Back
Top