none
How To Change A Progressbar color...

Answers

All replies

  • Change the color in the ProgressBar properties.  Choose a different color in the BackColor and ForeColor properties.
    Doug
    Friday, May 08, 2009 9:05 PM
  • Doug__, in that case you need to disable XP styles and themes because the ForeColor property will be overriden by XP Theme :(


    Thanks,
    A.m.a.L

    .Net Goodies
    [Remember to click "mark as answered" when you get a correct reply to your question]
    Friday, May 08, 2009 9:14 PM
  • You're right Amal...I had too many things going at the time and that slipped my mind.  Thanks!    :)
    Doug
    Friday, May 08, 2009 9:17 PM
  • :)

    I think its better to draw the progress bar using Graphics object.



    Thanks,
    A.m.a.L

    .Net Goodies
    [Remember to click "mark as answered" when you get a correct reply to your question]
    Friday, May 08, 2009 9:19 PM
  • I have drawn my own ProgressBar in the past.  But I think for a lot of people here, that might be too advanced.  Wish I had some kind of code repository where I could store my code snippets for later use.
    Doug
    Friday, May 08, 2009 9:25 PM
  • Check this kb

    http://support.microsoft.com/kb/323088


    Thanks,
    A.m.a.L

    .Net Goodies
    [Remember to click "mark as answered" when you get a correct reply to your question]
    • Marked as answer by Tj.. _ Saturday, May 09, 2009 10:21 PM
    Friday, May 08, 2009 9:37 PM
  • Another example

    http://www.dreamincode.net/forums/showtopic59606.htm

    One more

    http://vbnet.mvps.org/index.html?code/forms/psfloodmdi.htm



    Thanks,
    A.m.a.L

    .Net Goodies
    [Remember to click "mark as answered" when you get a correct reply to your question]
    Friday, May 08, 2009 9:40 PM
  • You can do a progressbar with a linear gradient as well . For example this usercontrol .

    Public Class Pbar
        Private _maximum As Integer = 100
        Private _minimum As Integer = 0
        Private _Value As Integer = 1
        Private _Color1 As Color = Color.Black
        Private _Color2 As Color = Color.White
        Private _BorderColor As Color = Color.Black
    
        Public Sub New()
    
            ' This call is required by the Windows Form Designer.
            InitializeComponent()
    
            ' Add any initialization after the InitializeComponent() call.
            Me.Width = 100
            Me.Height = 20
    
        End Sub
    
        Public Property Maximum() As Integer
            Get
                Return _maximum
            End Get
            Set(ByVal value As Integer)
                If value <= _minimum Then value = _minimum + 1
                _maximum = value
            End Set
        End Property
    
        Public Property minimum() As Integer
            Get
                Return _minimum
            End Get
            Set(ByVal value As Integer)
                If value >= _maximum Then value = _maximum - 1
                _minimum = value
            End Set
        End Property
    
        Public Property Value() As Integer
            Get
                Return _Value
            End Get
            Set(ByVal value As Integer)
                If value > _maximum Then value = _maximum
                If value < _minimum Then value = _minimum
                _Value = value
                Me.Invalidate()
            End Set
        End Property
    
        Public Property Color1() As Color
            Get
                Return _Color1
            End Get
            Set(ByVal value As Color)
                _Color1 = value
            End Set
        End Property
    
        Public Property Color2() As Color
            Get
                Return _Color2
            End Get
            Set(ByVal value As Color)
                _Color2 = value
            End Set
        End Property
    
        Public Property BorderColor() As Color
            Get
                Return _BorderColor
            End Get
            Set(ByVal value As Color)
                _BorderColor = value
            End Set
        End Property
    
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
    
            Dim steps As Double = Me.Width / _maximum - _minimum
            Dim w As Integer = CInt(steps * _Value)
            If w > 0 Then
                Dim rect As New Rectangle(0, 0, w, Me.Height)
                Dim GRBrush As New System.Drawing.Drawing2D.LinearGradientBrush(rect, _Color1, _Color2, Drawing2D.LinearGradientMode.Vertical)
                e.Graphics.FillRectangle(GRBrush, rect)
            End If
            Dim r As New Rectangle(1, 1, Me.Width - 2, Me.Height - 2)
    
            e.Graphics.DrawRectangle(New Pen(_BorderColor, 2), r)
    
        End Sub
    End Class
    

    Coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Friday, May 08, 2009 10:15 PM
  • I don't want to disable vista/ xp style theme AT ALL if someone could help me with that.....It's for a web browser ...
    • Proposed as answer by tegezee Saturday, May 09, 2009 10:49 PM
    Saturday, May 09, 2009 3:41 AM
  • I've checked thru the threads of this forum and found that the only way to be able to change the color of the progress bar is to disable the XP theme or to create your own ProgressBar control.  If you want to create your own control, click here (the link Amal gave above) and follow the instructions, or use the code bdbodger provided above to create a user control.

    You could also do a web search to find example code using Google or Yahoo or MS Live Search or other.



    Doug
    Saturday, May 09, 2009 7:52 AM