none
Visual Studio 2010 and Progress Bar Color

    Question

  • Hi,

    I am using Visual Studio 2010 (VB Project) and have a form, I need to have a progress bar on it.

    How I can change the COLOR of progress bar from the default green color to a different color?

    Thanks for help.


    N.A.Malik
    Thursday, June 02, 2011 5:08 PM

Answers

  • Hi,

    so, why not draw the marquee-style yourself? Her's something to start, an updated and translated version of my above code:

    Partial Public Class Form1
      Inherits Form
      Private newProgressBar1 As New NewProgressBar()
      Private b As New Button()
    
      Public Sub New()
        InitializeComponent()
    
        newProgressBar1.Location = New Point(24, 24)
        newProgressBar1.Width = 200
        Me.Controls.Add(newProgressBar1)
        newProgressBar1.ShowText = True
        newProgressBar1.ForeColor = Color.White
        newProgressBar1.Style = ProgressBarStyle.Marquee
        newProgressBar1.Color1 = Color.FromArgb(24, 0, 0, 255)
        newProgressBar1.Color2 = Color.FromArgb(255, 0, 0, 255)
        newProgressBar1.Color3 = Color.FromArgb(24, 0, 0, 255)
        newProgressBar1.MarqueeWidth = 70
        newProgressBar1.MarqueeAnimationSpeed = 50
        newProgressBar1.MarqueeIncrement = 2
        'newProgressBar1.DrawBlendShadow = false;
    
        b.Location = New Point(24, 100)
        b.Text = "b"
        Me.Controls.Add(b)
        AddHandler b.Click, AddressOf b_Click
      End Sub
    
      Private Sub b_Click(sender As Object, e As EventArgs)
        newProgressBar1.Style = ProgressBarStyle.Blocks
        If newProgressBar1.Value < newProgressBar1.Maximum Then
          newProgressBar1.Value += 10
        End If
      End Sub
    End Class
    
    Public Class NewProgressBar
      Inherits ProgressBar
      Public Property Percentage() As Integer
        Get
          Return m_Percentage
        End Get
        Set(value As Integer)
          m_Percentage = value
        End Set
      End Property
      Private m_Percentage As Integer
      Public Property ShowText() As Boolean
        Get
          Return m_ShowText
        End Get
        Set(value As Boolean)
          m_ShowText = value
        End Set
      End Property
      Private m_ShowText As Boolean
    
      Public Property Color1() As Color
        Get
          Return m_Color1
        End Get
        Set(value As Color)
          m_Color1 = value
        End Set
      End Property
      Private m_Color1 As Color
      Public Property Color2() As Color
        Get
          Return m_Color2
        End Get
        Set(value As Color)
          m_Color2 = value
        End Set
      End Property
      Private m_Color2 As Color
      Public Property Color3() As Color
        Get
          Return m_Color3
        End Get
        Set(value As Color)
          m_Color3 = value
        End Set
      End Property
      Private m_Color3 As Color
    
      Public Property Position1() As Single
        Get
          Return m_Position1
        End Get
        Set(value As Single)
          m_Position1 = value
        End Set
      End Property
      Private m_Position1 As Single
      Public Property Position2() As Single
        Get
          Return m_Position2
        End Get
        Set(value As Single)
          m_Position2 = value
        End Set
      End Property
      Private m_Position2 As Single
      Public Property Position3() As Single
        Get
          Return m_Position3
        End Get
        Set(value As Single)
          m_Position3 = value
        End Set
      End Property
      Private m_Position3 As Single
    
      Private t As New Timer()
      Private _rec As RectangleF
    
      Private _marqueeWidth As Single = 0
      Public Property MarqueeWidth() As Single
        Get
          Return _marqueeWidth
        End Get
        Set(value As Single)
          _marqueeWidth = value
          If Me.MarqueeWidth > 0 Then
            _rec = New RectangleF(-Me.MarqueeWidth, 0, Me.MarqueeWidth, Me.ClientSize.Height)
          End If
        End Set
      End Property
    
      Private _style As ProgressBarStyle = ProgressBarStyle.Blocks
      Public Shadows Property Style() As ProgressBarStyle
        Get
          Return _style
        End Get
        Set(value As ProgressBarStyle)
          _style = value
          If _style = ProgressBarStyle.Marquee Then
            If Me.MarqueeWidth > 0 Then
              _rec = New RectangleF(-Me.MarqueeWidth, 0, Me.MarqueeWidth, Me.ClientSize.Height)
            End If
            t.Start()
          Else
            t.[Stop]()
          End If
        End Set
      End Property
    
      Private _marqueeAnimationSpeed As Integer = 100
      Public Shadows Property MarqueeAnimationSpeed() As Integer
        Get
          Return _marqueeAnimationSpeed
        End Get
        Set(value As Integer)
          _marqueeAnimationSpeed = value
          t.Interval = _marqueeAnimationSpeed
        End Set
      End Property
    
      Public Property MarqueeIncrement() As Integer
        Get
          Return m_MarqueeIncrement
        End Get
        Set(value As Integer)
          m_MarqueeIncrement = value
        End Set
      End Property
      Private m_MarqueeIncrement As Integer
    
      Public Shadows Property Value() As Integer
        Get
          Return Me.Percentage
        End Get
        Set(value As Integer)
          Me.Percentage = value
          Me.Invalidate()
        End Set
      End Property
    
      Public Property DrawBlendShadow() As Boolean
        Get
          Return m_DrawBlendShadow
        End Get
        Set(value As Boolean)
          m_DrawBlendShadow = value
        End Set
      End Property
      Private m_DrawBlendShadow As Boolean
    
      Public Sub New()
        Me.SetStyle(ControlStyles.UserPaint, True)
        Me.DoubleBuffered = True
        Me.Color1 = Color.Lime
        Me.Color2 = Color.Green
        Me.Color3 = Color.Red
        Me.Position1 = 0
        Me.Position2 = 0.55F
        Me.Position3 = 1.0F
        Me.MarqueeIncrement = 5
        Me.DrawBlendShadow = True
        _rec = New RectangleF(-Me.ClientSize.Width / 4.0F, 0, Me.ClientSize.Width / 4.0F, Me.ClientSize.Height)
        t.Interval = Me.MarqueeAnimationSpeed
        AddHandler t.Tick, AddressOf t_Tick
      End Sub
    
      Private Sub t_Tick(sender As Object, e As EventArgs)
        _rec = New RectangleF(_rec.X + Me.MarqueeIncrement, _rec.Y, _rec.Width, _rec.Height)
    
        If _rec.X > Me.ClientSize.Width + _rec.Width Then
          _rec.X = -_rec.Width
        End If
    
        Me.Invalidate()
      End Sub
    
      Protected Overrides Sub OnPaint(e As PaintEventArgs)
        Dim rec As Rectangle = e.ClipRectangle
    
        rec.Width = CInt(rec.Width * (CDbl(Value) / Maximum)) - 4
    
        If ProgressBarRenderer.IsSupported Then
          ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle)
        Else
          e.Graphics.DrawRectangle(Pens.Gray, 0, 0, Me.Width, Me.Height)
        End If
    
        rec.Height = rec.Height - 4
    
        If Me.Style <> ProgressBarStyle.Marquee Then
          Using l As New System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.Green, Color.Red, 0.0F)
            Dim lb As New System.Drawing.Drawing2D.ColorBlend()
            lb.Colors = New Color() {Color1, Color2, Color3}
            lb.Positions = New Single() {Position1, Position2, Position3}
            l.InterpolationColors = lb
    
            e.Graphics.FillRectangle(l, 2, 2, rec.Width, rec.Height)
          End Using
    
          Using l2 As New System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.FromArgb(147, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), System.Drawing.Drawing2D.LinearGradientMode.Vertical)
            Dim lb As New System.Drawing.Drawing2D.ColorBlend()
            lb.Colors = New Color() {Color.FromArgb(40, 255, 255, 255), Color.FromArgb(147, 255, 255, 255), Color.FromArgb(40, 255, 255, 255), Color.FromArgb(0, 255, 255, 255)}
            lb.Positions = New Single() {0, 0.12F, 0.39F, 1.0F}
            l2.InterpolationColors = lb
    
            l2.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile
            e.Graphics.FillRectangle(l2, 2, 2, rec.Width, rec.Height)
          End Using
    
          If Me.ShowText Then
            Using sb As New SolidBrush(Me.ForeColor)
              Dim sz As SizeF = e.Graphics.MeasureString(Percentage.ToString() + " %", Me.Font)
              e.Graphics.DrawString(Percentage.ToString() + " %", Me.Font, sb, New PointF((Me.Width - sz.Width) / 2.0F, (Me.Height - sz.Height) / 2.0F))
            End Using
          End If
        Else
          Using l As New System.Drawing.Drawing2D.LinearGradientBrush(_rec, Color.Green, Color.Red, 0.0F)
            Dim lb As New System.Drawing.Drawing2D.ColorBlend()
            lb.Colors = New Color() {Color1, Color2, Color3}
            lb.Positions = New Single() {Position1, Position2, Position3}
            l.InterpolationColors = lb
    
            e.Graphics.FillRectangle(l, _rec)
          End Using
    
          If DrawBlendShadow Then
            Using l2 As New System.Drawing.Drawing2D.LinearGradientBrush(_rec, Color.FromArgb(147, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), System.Drawing.Drawing2D.LinearGradientMode.Vertical)
              Dim lb As New System.Drawing.Drawing2D.ColorBlend()
              lb.Colors = New Color() {Color.FromArgb(40, 255, 255, 255), Color.FromArgb(147, 255, 255, 255), Color.FromArgb(40, 255, 255, 255), Color.FromArgb(0, 255, 255, 255)}
              lb.Positions = New Single() {0, 0.12F, 0.39F, 1.0F}
              l2.InterpolationColors = lb
    
              l2.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile
              e.Graphics.FillRectangle(l2, _rec)
            End Using
          End If
        End If
      End Sub
    
      Protected Overrides Sub Dispose(disposing As Boolean)
        t.Dispose()
    
        MyBase.Dispose(disposing)
      End Sub
    End Class
    
    
    
    

    Regards,

      Thorsten

    • Marked as answer by N A Malik Tuesday, June 07, 2011 6:37 PM
    Monday, June 06, 2011 2:37 AM

All replies

  • Have you tried ProgressBar.ForeColor or BackColor?
    Amit Govil (amit.govil@hotmail.com)
    Thursday, June 02, 2011 5:26 PM
  • Have you tried ProgressBar.ForeColor or BackColor?
    Amit Govil (amit.govil@hotmail.com)


    Hi,

    It didnt work for me :(


    N.A.Malik
    Thursday, June 02, 2011 10:07 PM
  • Refer following link

    http://stackoverflow.com/questions/778678/how-to-change-the-color-of-progressbar-in-c-net-3-5


    Gaurav Khanna


    It talks about C# I am using VB,

    Any more hints?


    N.A.Malik
    Thursday, June 02, 2011 10:07 PM
  • It talks about C# I am using VB,

    Any more hints?


    N.A.Malik

    You can use C# to VB.NET Converter to convert the code

    http://www.developerfusion.com/tools/convert/csharp-to-vb/


    Gaurav Khanna
    Friday, June 03, 2011 5:25 AM
  • No, it doesn't.  The ProgressBar control only works one way and that's using one of the colours from the Windows Colour Scheme - you cannot change the colour, without crippling the visual styles in your entire application.  Nor can you get a numeric value (progress percentage) overlaid over the top. 

    This is, IMHO, the thin end of the wedge as we start to see Controls that we've relied on for years gradually have their functionality whittled away and dumbed down so that Our Friends in Redmond can put everything into The Cloud (and charge us for the privilege).  Just look at where MS Office if going.

    I wound up digging out my old VB4 code for a progress bar and now I use that!

     


    Regards, Phill W.
    Friday, June 03, 2011 1:00 PM
  • Hi,

    Plz guys, tell me the simplest way to change the progress bar color in MS Visual Studio 2010 (VB Project).


    N.A.Malik
    Friday, June 03, 2011 11:18 PM
  • Hi,

    there are just the two mentioned ways. Either disable VisualStyles or draw the ProgressBar yourself. Sodmething to start with:

      public partial class Form1 : Form
      {
        private NewProgressBar newProgressBar1 = new NewProgressBar();
        Button b = new Button();
        public Form1()
        {
          InitializeComponent();
    
          newProgressBar1.Location = new Point(24, 24);
          newProgressBar1.Width = 200;
          this.Controls.Add(newProgressBar1);
          newProgressBar1.ShowText = true;
          newProgressBar1.ForeColor = Color.White;
    
          b.Location = new Point(24, 100);
          b.Text = "b";
          this.Controls.Add(b);
          b.Click += new EventHandler(b_Click);
        }
    
        void b_Click(object sender, EventArgs e)
        {
          if (newProgressBar1.Value < newProgressBar1.Maximum)
            newProgressBar1.Value += 10;
        }
      }
    
      public class NewProgressBar : ProgressBar
      {
        public int Percentage { get; set; }
        public bool ShowText { get; set; }
    
        public Color Color1 { get; set; }
        public Color Color2 { get; set; }
        public Color Color3 { get; set; }
    
        public float Position1 { get; set; }
        public float Position2 { get; set; }
        public float Position3 { get; set; }
    
        public new int Value
        {
          get { return this.Percentage; }
          set
          {
            this.Percentage = value;
            this.Invalidate();
          }
        }
    
        public NewProgressBar()
        {
          this.SetStyle(ControlStyles.UserPaint, true);
          this.DoubleBuffered = true;
          this.Color1 = Color.Lime;
          this.Color2 = Color.Green;
          this.Color3 = Color.Red;
          this.Position1 = 0;
          this.Position2 = 0.55F;
          this.Position3 = 1.0F;
        }
    
        protected override void OnPaint(PaintEventArgs e)
        {
          Rectangle rec = e.ClipRectangle;
    
          rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4;
    
          if (ProgressBarRenderer.IsSupported)
            ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
          else
            e.Graphics.DrawRectangle(Pens.Gray, 0, 0, this.Width, this.Height);
    
          rec.Height = rec.Height - 4;
    
          using (System.Drawing.Drawing2D.LinearGradientBrush l =
           new System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.Green, Color.Red, 0F))
          {
            System.Drawing.Drawing2D.ColorBlend lb = new System.Drawing.Drawing2D.ColorBlend();
            lb.Colors = new Color[] { Color1, Color2, Color3 };
            lb.Positions = new float[] { Position1, Position2, Position3 };
            l.InterpolationColors = lb;
    
            e.Graphics.FillRectangle(l, 2, 2, rec.Width, rec.Height);
          }
    
          using (System.Drawing.Drawing2D.LinearGradientBrush l2 =
           new System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.FromArgb(147, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), System.Drawing.Drawing2D.LinearGradientMode.Vertical))
          {
            System.Drawing.Drawing2D.ColorBlend lb = new System.Drawing.Drawing2D.ColorBlend();
            lb.Colors = new Color[] { Color.FromArgb(40, 255, 255, 255), Color.FromArgb(147, 255, 255, 255), 
               Color.FromArgb(40, 255, 255, 255), Color.FromArgb(0, 255, 255, 255) };
            lb.Positions = new float[] { 0, 0.12F, 0.39F, 1.0F };
            l2.InterpolationColors = lb;
    
            l2.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
            e.Graphics.FillRectangle(l2, 2, 2, rec.Width, rec.Height);
          }
    
          if (this.ShowText)
          {
            using (SolidBrush sb = new SolidBrush(this.ForeColor))
            {
              SizeF sz = e.Graphics.MeasureString(Percentage.ToString() + " %", this.Font);
              e.Graphics.DrawString(Percentage.ToString() + " %", this.Font, sb,
               new PointF((this.Width - sz.Width) / 2F, (this.Height - sz.Height) / 2F));
            }
          }
    
        }
      }
     

    Regards,

      Thorsten


    Friday, June 03, 2011 11:30 PM
  • Hi,

    Plz guys, tell me the simplest way to change the progress bar color in MS Visual Studio 2010 (VB Project).


    N.A.Malik

    Here is the VB.NET code from link in my previous post

    Public Class NewProgressBar
        Inherits ProgressBar
        Public Sub New()
            Me.SetStyle(ControlStyles.UserPaint, True)
        End Sub
     
        Protected Overrides Sub OnPaint(e As PaintEventArgs)
            Dim rec As Rectangle = e.ClipRectangle
     
            rec.Width = CInt(Math.Truncate(rec.Width * (CDbl(Value) / Maximum))) - 4
            If ProgressBarRenderer.IsSupported Then
                ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle)
            End If
            rec.Height = rec.Height - 4
            e.Graphics.FillRectangle(Brushes.Yellow, 2, 2, rec.Width, rec.Height)
        End Sub
    End Class

    You can change color from Yellow to any other color you want for progressbar.


    Gaurav Khanna
    Saturday, June 04, 2011 5:01 AM
  • Hi,

    Plz guys, tell me the simplest way to change the progress bar color in MS Visual Studio 2010 (VB Project).


    N.A.Malik

    Here is the VB.NET code from link in my previous post

     

    Public Class NewProgressBar
        Inherits ProgressBar
        Public Sub New()
            Me.SetStyle(ControlStyles.UserPaint, True)
        End Sub
     
        Protected Overrides Sub OnPaint(e As PaintEventArgs)
            Dim rec As Rectangle = e.ClipRectangle
     
            rec.Width = CInt(Math.Truncate(rec.Width * (CDbl(Value) / Maximum))) - 4
            If ProgressBarRenderer.IsSupported Then
                ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle)
            End If
            rec.Height = rec.Height - 4
            e.Graphics.FillRectangle(Brushes.Yellow, 2, 2, rec.Width, rec.Height)
        End Sub
    End Class

     

    You can change color from Yellow to any other color you want for progressbar.


    Gaurav Khanna


    Hi

    Thank you for help.

    I checked this and it do not support the Progress Bar Style MARQUEE. Even I have used


    Style = ProgressBarStyle.Marquee

     

    Can you please advise me further?


    N.A.Malik
    Saturday, June 04, 2011 1:54 PM
  • You can refer links in following thread. It could help you.

    http://social.msdn.microsoft.com/forums/en-US/winforms/thread/c2d6374b-aaa7-41b6-9a5d-413fe449dc3a/

     


    Gaurav Khanna

    Saturday, June 04, 2011 6:19 PM
  • Hi

    here is the same class on converted in  C#

    public class NewProgressBar : ProgressBar
    {
    	public NewProgressBar()
    	{
    		this.SetStyle(ControlStyles.UserPaint, true);
    	}
    
    	protected override void OnPaint(PaintEventArgs e)
    	{
    		Rectangle rec = e.ClipRectangle;
    
    		rec.Width = Convert.ToInt32(Math.Truncate(rec.Width * (Convert.ToDouble(Value) / Maximum))) - 4;
    		if (ProgressBarRenderer.IsSupported) {
    			ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
    		}
    		rec.Height = rec.Height - 4;
    		e.Graphics.FillRectangle(Brushes.Yellow, 2, 2, rec.Width, rec.Height);
    	}
    }
    


    The complexity resides in the simplicity Follow me at: http://smartssolutions.blogspot.com
    Saturday, June 04, 2011 9:31 PM
  • Hi

    here is the same class on converted in  C#

     

    public class NewProgressBar : ProgressBar
    {
    	public NewProgressBar()
    	{
    		this.SetStyle(ControlStyles.UserPaint, true);
    	}
    
    	protected override void OnPaint(PaintEventArgs e)
    	{
    		Rectangle rec = e.ClipRectangle;
    
    		rec.Width = Convert.ToInt32(Math.Truncate(rec.Width * (Convert.ToDouble(Value) / Maximum))) - 4;
    		if (ProgressBarRenderer.IsSupported) {
    			ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
    		}
    		rec.Height = rec.Height - 4;
    		e.Graphics.FillRectangle(Brushes.Yellow, 2, 2, rec.Width, rec.Height);
    	}
    }
    

     


    The complexity resides in the simplicity Follow me at: http://smartssolutions.blogspot.com


    Hi,

    Let say I need this Progress bar that is in YELLO color.

    Is it possible that yello color rectangle shrikns and expands for infinite number of time ? May be infinite loop? So it may look like the Marquee Progress bar style?

    If yes, please share it with me.

    Thank you.


    N.A.Malik
    Sunday, June 05, 2011 6:50 PM
  • Hi,

    Plz guys, tell me the simplest way to change the progress bar color in MS Visual Studio 2010 (VB Project).


    N.A.Malik

    Here is the VB.NET code from link in my previous post

     

    Public Class NewProgressBar
        Inherits ProgressBar
        Public Sub New()
            Me.SetStyle(ControlStyles.UserPaint, True)
        End Sub
     
        Protected Overrides Sub OnPaint(e As PaintEventArgs)
            Dim rec As Rectangle = e.ClipRectangle
     
            rec.Width = CInt(Math.Truncate(rec.Width * (CDbl(Value) / Maximum))) - 4
            If ProgressBarRenderer.IsSupported Then
                ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle)
            End If
            rec.Height = rec.Height - 4
            e.Graphics.FillRectangle(Brushes.Yellow, 2, 2, rec.Width, rec.Height)
        End Sub
    End Class

     

    You can change color from Yellow to any other color you want for progressbar.


    Gaurav Khanna

    Hi,

    Let say I need this Progress bar that is in YELLO color.

    Is it possible that yello color rectangle shrikns and expands for infinite number of time ? May be infinite loop? So it may look like the Marquee Progress bar style?

    If yes, please share it with me.

    Thank you.


    N.A.Malik
    Sunday, June 05, 2011 6:50 PM
  • Hi,

    so, why not draw the marquee-style yourself? Her's something to start, an updated and translated version of my above code:

    Partial Public Class Form1
      Inherits Form
      Private newProgressBar1 As New NewProgressBar()
      Private b As New Button()
    
      Public Sub New()
        InitializeComponent()
    
        newProgressBar1.Location = New Point(24, 24)
        newProgressBar1.Width = 200
        Me.Controls.Add(newProgressBar1)
        newProgressBar1.ShowText = True
        newProgressBar1.ForeColor = Color.White
        newProgressBar1.Style = ProgressBarStyle.Marquee
        newProgressBar1.Color1 = Color.FromArgb(24, 0, 0, 255)
        newProgressBar1.Color2 = Color.FromArgb(255, 0, 0, 255)
        newProgressBar1.Color3 = Color.FromArgb(24, 0, 0, 255)
        newProgressBar1.MarqueeWidth = 70
        newProgressBar1.MarqueeAnimationSpeed = 50
        newProgressBar1.MarqueeIncrement = 2
        'newProgressBar1.DrawBlendShadow = false;
    
        b.Location = New Point(24, 100)
        b.Text = "b"
        Me.Controls.Add(b)
        AddHandler b.Click, AddressOf b_Click
      End Sub
    
      Private Sub b_Click(sender As Object, e As EventArgs)
        newProgressBar1.Style = ProgressBarStyle.Blocks
        If newProgressBar1.Value < newProgressBar1.Maximum Then
          newProgressBar1.Value += 10
        End If
      End Sub
    End Class
    
    Public Class NewProgressBar
      Inherits ProgressBar
      Public Property Percentage() As Integer
        Get
          Return m_Percentage
        End Get
        Set(value As Integer)
          m_Percentage = value
        End Set
      End Property
      Private m_Percentage As Integer
      Public Property ShowText() As Boolean
        Get
          Return m_ShowText
        End Get
        Set(value As Boolean)
          m_ShowText = value
        End Set
      End Property
      Private m_ShowText As Boolean
    
      Public Property Color1() As Color
        Get
          Return m_Color1
        End Get
        Set(value As Color)
          m_Color1 = value
        End Set
      End Property
      Private m_Color1 As Color
      Public Property Color2() As Color
        Get
          Return m_Color2
        End Get
        Set(value As Color)
          m_Color2 = value
        End Set
      End Property
      Private m_Color2 As Color
      Public Property Color3() As Color
        Get
          Return m_Color3
        End Get
        Set(value As Color)
          m_Color3 = value
        End Set
      End Property
      Private m_Color3 As Color
    
      Public Property Position1() As Single
        Get
          Return m_Position1
        End Get
        Set(value As Single)
          m_Position1 = value
        End Set
      End Property
      Private m_Position1 As Single
      Public Property Position2() As Single
        Get
          Return m_Position2
        End Get
        Set(value As Single)
          m_Position2 = value
        End Set
      End Property
      Private m_Position2 As Single
      Public Property Position3() As Single
        Get
          Return m_Position3
        End Get
        Set(value As Single)
          m_Position3 = value
        End Set
      End Property
      Private m_Position3 As Single
    
      Private t As New Timer()
      Private _rec As RectangleF
    
      Private _marqueeWidth As Single = 0
      Public Property MarqueeWidth() As Single
        Get
          Return _marqueeWidth
        End Get
        Set(value As Single)
          _marqueeWidth = value
          If Me.MarqueeWidth > 0 Then
            _rec = New RectangleF(-Me.MarqueeWidth, 0, Me.MarqueeWidth, Me.ClientSize.Height)
          End If
        End Set
      End Property
    
      Private _style As ProgressBarStyle = ProgressBarStyle.Blocks
      Public Shadows Property Style() As ProgressBarStyle
        Get
          Return _style
        End Get
        Set(value As ProgressBarStyle)
          _style = value
          If _style = ProgressBarStyle.Marquee Then
            If Me.MarqueeWidth > 0 Then
              _rec = New RectangleF(-Me.MarqueeWidth, 0, Me.MarqueeWidth, Me.ClientSize.Height)
            End If
            t.Start()
          Else
            t.[Stop]()
          End If
        End Set
      End Property
    
      Private _marqueeAnimationSpeed As Integer = 100
      Public Shadows Property MarqueeAnimationSpeed() As Integer
        Get
          Return _marqueeAnimationSpeed
        End Get
        Set(value As Integer)
          _marqueeAnimationSpeed = value
          t.Interval = _marqueeAnimationSpeed
        End Set
      End Property
    
      Public Property MarqueeIncrement() As Integer
        Get
          Return m_MarqueeIncrement
        End Get
        Set(value As Integer)
          m_MarqueeIncrement = value
        End Set
      End Property
      Private m_MarqueeIncrement As Integer
    
      Public Shadows Property Value() As Integer
        Get
          Return Me.Percentage
        End Get
        Set(value As Integer)
          Me.Percentage = value
          Me.Invalidate()
        End Set
      End Property
    
      Public Property DrawBlendShadow() As Boolean
        Get
          Return m_DrawBlendShadow
        End Get
        Set(value As Boolean)
          m_DrawBlendShadow = value
        End Set
      End Property
      Private m_DrawBlendShadow As Boolean
    
      Public Sub New()
        Me.SetStyle(ControlStyles.UserPaint, True)
        Me.DoubleBuffered = True
        Me.Color1 = Color.Lime
        Me.Color2 = Color.Green
        Me.Color3 = Color.Red
        Me.Position1 = 0
        Me.Position2 = 0.55F
        Me.Position3 = 1.0F
        Me.MarqueeIncrement = 5
        Me.DrawBlendShadow = True
        _rec = New RectangleF(-Me.ClientSize.Width / 4.0F, 0, Me.ClientSize.Width / 4.0F, Me.ClientSize.Height)
        t.Interval = Me.MarqueeAnimationSpeed
        AddHandler t.Tick, AddressOf t_Tick
      End Sub
    
      Private Sub t_Tick(sender As Object, e As EventArgs)
        _rec = New RectangleF(_rec.X + Me.MarqueeIncrement, _rec.Y, _rec.Width, _rec.Height)
    
        If _rec.X > Me.ClientSize.Width + _rec.Width Then
          _rec.X = -_rec.Width
        End If
    
        Me.Invalidate()
      End Sub
    
      Protected Overrides Sub OnPaint(e As PaintEventArgs)
        Dim rec As Rectangle = e.ClipRectangle
    
        rec.Width = CInt(rec.Width * (CDbl(Value) / Maximum)) - 4
    
        If ProgressBarRenderer.IsSupported Then
          ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle)
        Else
          e.Graphics.DrawRectangle(Pens.Gray, 0, 0, Me.Width, Me.Height)
        End If
    
        rec.Height = rec.Height - 4
    
        If Me.Style <> ProgressBarStyle.Marquee Then
          Using l As New System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.Green, Color.Red, 0.0F)
            Dim lb As New System.Drawing.Drawing2D.ColorBlend()
            lb.Colors = New Color() {Color1, Color2, Color3}
            lb.Positions = New Single() {Position1, Position2, Position3}
            l.InterpolationColors = lb
    
            e.Graphics.FillRectangle(l, 2, 2, rec.Width, rec.Height)
          End Using
    
          Using l2 As New System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.FromArgb(147, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), System.Drawing.Drawing2D.LinearGradientMode.Vertical)
            Dim lb As New System.Drawing.Drawing2D.ColorBlend()
            lb.Colors = New Color() {Color.FromArgb(40, 255, 255, 255), Color.FromArgb(147, 255, 255, 255), Color.FromArgb(40, 255, 255, 255), Color.FromArgb(0, 255, 255, 255)}
            lb.Positions = New Single() {0, 0.12F, 0.39F, 1.0F}
            l2.InterpolationColors = lb
    
            l2.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile
            e.Graphics.FillRectangle(l2, 2, 2, rec.Width, rec.Height)
          End Using
    
          If Me.ShowText Then
            Using sb As New SolidBrush(Me.ForeColor)
              Dim sz As SizeF = e.Graphics.MeasureString(Percentage.ToString() + " %", Me.Font)
              e.Graphics.DrawString(Percentage.ToString() + " %", Me.Font, sb, New PointF((Me.Width - sz.Width) / 2.0F, (Me.Height - sz.Height) / 2.0F))
            End Using
          End If
        Else
          Using l As New System.Drawing.Drawing2D.LinearGradientBrush(_rec, Color.Green, Color.Red, 0.0F)
            Dim lb As New System.Drawing.Drawing2D.ColorBlend()
            lb.Colors = New Color() {Color1, Color2, Color3}
            lb.Positions = New Single() {Position1, Position2, Position3}
            l.InterpolationColors = lb
    
            e.Graphics.FillRectangle(l, _rec)
          End Using
    
          If DrawBlendShadow Then
            Using l2 As New System.Drawing.Drawing2D.LinearGradientBrush(_rec, Color.FromArgb(147, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), System.Drawing.Drawing2D.LinearGradientMode.Vertical)
              Dim lb As New System.Drawing.Drawing2D.ColorBlend()
              lb.Colors = New Color() {Color.FromArgb(40, 255, 255, 255), Color.FromArgb(147, 255, 255, 255), Color.FromArgb(40, 255, 255, 255), Color.FromArgb(0, 255, 255, 255)}
              lb.Positions = New Single() {0, 0.12F, 0.39F, 1.0F}
              l2.InterpolationColors = lb
    
              l2.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile
              e.Graphics.FillRectangle(l2, _rec)
            End Using
          End If
        End If
      End Sub
    
      Protected Overrides Sub Dispose(disposing As Boolean)
        t.Dispose()
    
        MyBase.Dispose(disposing)
      End Sub
    End Class
    
    
    
    

    Regards,

      Thorsten

    • Marked as answer by N A Malik Tuesday, June 07, 2011 6:37 PM
    Monday, June 06, 2011 2:37 AM
  • Hi N.A.Malik,

    Welcome to the MSDN Forum.

    You can't change the color through the properties. You can change the default color by redrawing it.

    There is an sample code on codeproject and you can fix the project and study on how to draw it:

    Custom ProgressBar Control:
    http://www.codeproject.com/KB/progress/ProgBarPlus.aspx

    There are almost all kinds of the progress bars in the test demon.

    If you have any questions, please feel free to let me know.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 06, 2011 7:08 AM
  • Hi

    I did just the translation from VB to C#, to be honest I didn't test this staff


    The complexity resides in the simplicity Follow me at: http://smartssolutions.blogspot.com
    Monday, June 06, 2011 9:19 AM
  • Hi again

    I rectified a little bit the code so that the user could set the color through a BackgoundColor property

     

    public class NewProgressBar : ProgressBar
      {
       public NewProgressBar()
       {
        this.SetStyle(ControlStyles.UserPaint, true);
       }
       //I added a new property to the progress bar to let the user change the color
       public Brush BackGroundColor 
       { 
        get; 
        set;
       }
    
       protected override void OnPaint(PaintEventArgs e)
       {
        Rectangle rec = e.ClipRectangle;
    
        rec.Width = Convert.ToInt32(Math.Truncate(rec.Width * (Convert.ToDouble(Value) / Maximum))) - 4;
        if (ProgressBarRenderer.IsSupported)
        {
         ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
        }
        rec.Height = rec.Height - 4;
    
        if (BackColor==null)
        {
         e.Graphics.FillRectangle(Brushes.YellowGreen, 2, 2, rec.Width, rec.Height);
        }
        else
        {
         e.Graphics.FillRectangle(BackGroundColor, 2, 2, rec.Width, rec.Height);
        }
       }
    
      }
    
    Reguards

     


    The complexity resides in the simplicity Follow me at: http://smartssolutions.blogspot.com
    Monday, June 06, 2011 9:36 AM
  • Hi,

    there are just the two mentioned ways. Either disable VisualStyles or draw the ProgressBar yourself. Sodmething to start with:

     

     public partial class Form1 : Form
     {
     private NewProgressBar newProgressBar1 = new NewProgressBar();
     Button b = new Button();
     public Form1()
     {
      InitializeComponent();
    
      newProgressBar1.Location = new Point(24, 24);
      newProgressBar1.Width = 200;
      this.Controls.Add(newProgressBar1);
      newProgressBar1.ShowText = true;
      newProgressBar1.ForeColor = Color.White;
    
      b.Location = new Point(24, 100);
      b.Text = "b";
      this.Controls.Add(b);
      b.Click += new EventHandler(b_Click);
     }
    
     void b_Click(object sender, EventArgs e)
     {
      if (newProgressBar1.Value < newProgressBar1.Maximum)
      newProgressBar1.Value += 10;
     }
     }
    
     public class NewProgressBar : ProgressBar
     {
     public int Percentage { get; set; }
     public bool ShowText { get; set; }
    
     public Color Color1 { get; set; }
     public Color Color2 { get; set; }
     public Color Color3 { get; set; }
    
     public float Position1 { get; set; }
     public float Position2 { get; set; }
     public float Position3 { get; set; }
    
     public new int Value
     {
      get { return this.Percentage; }
      set
      {
      this.Percentage = value;
      this.Invalidate();
      }
     }
    
     public NewProgressBar()
     {
      this.SetStyle(ControlStyles.UserPaint, true);
      this.DoubleBuffered = true;
      this.Color1 = Color.Lime;
      this.Color2 = Color.Green;
      this.Color3 = Color.Red;
      this.Position1 = 0;
      this.Position2 = 0.55F;
      this.Position3 = 1.0F;
     }
    
     protected override void OnPaint(PaintEventArgs e)
     {
      Rectangle rec = e.ClipRectangle;
    
      rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4;
    
      if (ProgressBarRenderer.IsSupported)
      ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
      else
      e.Graphics.DrawRectangle(Pens.Gray, 0, 0, this.Width, this.Height);
    
      rec.Height = rec.Height - 4;
    
      using (System.Drawing.Drawing2D.LinearGradientBrush l =
      new System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.Green, Color.Red, 0F))
      {
      System.Drawing.Drawing2D.ColorBlend lb = new System.Drawing.Drawing2D.ColorBlend();
      lb.Colors = new Color[] { Color1, Color2, Color3 };
      lb.Positions = new float[] { Position1, Position2, Position3 };
      l.InterpolationColors = lb;
    
      e.Graphics.FillRectangle(l, 2, 2, rec.Width, rec.Height);
      }
    
      using (System.Drawing.Drawing2D.LinearGradientBrush l2 =
      new System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.FromArgb(147, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), System.Drawing.Drawing2D.LinearGradientMode.Vertical))
      {
      System.Drawing.Drawing2D.ColorBlend lb = new System.Drawing.Drawing2D.ColorBlend();
      lb.Colors = new Color[] { Color.FromArgb(40, 255, 255, 255), Color.FromArgb(147, 255, 255, 255), 
       Color.FromArgb(40, 255, 255, 255), Color.FromArgb(0, 255, 255, 255) };
      lb.Positions = new float[] { 0, 0.12F, 0.39F, 1.0F };
      l2.InterpolationColors = lb;
    
      l2.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
      e.Graphics.FillRectangle(l2, 2, 2, rec.Width, rec.Height);
      }
    
      if (this.ShowText)
      {
      using (SolidBrush sb = new SolidBrush(this.ForeColor))
      {
       SizeF sz = e.Graphics.MeasureString(Percentage.ToString() + " %", this.Font);
       e.Graphics.DrawString(Percentage.ToString() + " %", this.Font, sb,
       new PointF((this.Width - sz.Width) / 2F, (this.Height - sz.Height) / 2F));
      }
      }
    
     }
     }
    
     

     

    Regards,

      Thorsten


    -------------------------------------------------------------------------------
    Thank you for the wonderful help. I think I got it what I was looking for. Amazing it works fine. Just got one issue in the Designer, I can not see the Form1 in designer and got the following error. But If i try to execute it, it works fine.

    1 Error The type Form1 is made of several partial classes in the same file. Instances of this error (1) 1. Show Call Stack at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager) at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload) Help with this error MSDN Help


    N.A.Malik
    Monday, June 06, 2011 2:28 PM
  • Hi,

    ok, what you could do is to (in your OP you said it is a VB-project, so I changed the language in my previous post to vb, if you need it in c#, tell me, I'll repost the code in this language then):

    create a new win-forms-project and add a new Class named NewProgressBar. In the codeview of this class delete all and paste (only) the code for the class NewProgressBar from my previous post.

    Build the project and switch to Designe-view of Form 1

    Scroll up the toolbox to its top and drag a "NewProgressBar" to your Form.

    Set the Style-Property and the other Properties you want to and run the Project...

    Note: Better set the marquee intepolation-colors in code, cause the Dialog in the PropertiesWindow does not provide alpha-setting.

    Regards,

      Thorsten

    Monday, June 06, 2011 10:48 PM
  • Hi,

    so, why not draw the marquee-style yourself? Her's something to start, an updated and translated version of my above code:

    Partial Public Class Form1
     Inherits Form
     Private newProgressBar1 As New NewProgressBar()
     Private b As New Button()
    
     Public Sub New()
      InitializeComponent()
    
      newProgressBar1.Location = New Point(24, 24)
      newProgressBar1.Width = 200
      Me.Controls.Add(newProgressBar1)
      newProgressBar1.ShowText = True
      newProgressBar1.ForeColor = Color.White
      newProgressBar1.Style = ProgressBarStyle.Marquee
      newProgressBar1.Color1 = Color.FromArgb(24, 0, 0, 255)
      newProgressBar1.Color2 = Color.FromArgb(255, 0, 0, 255)
      newProgressBar1.Color3 = Color.FromArgb(24, 0, 0, 255)
      newProgressBar1.MarqueeWidth = 70
      newProgressBar1.MarqueeAnimationSpeed = 50
      newProgressBar1.MarqueeIncrement = 2
      'newProgressBar1.DrawBlendShadow = false;
    
      b.Location = New Point(24, 100)
      b.Text = "b"
      Me.Controls.Add(b)
      AddHandler b.Click, AddressOf b_Click
     End Sub
    
     Private Sub b_Click(sender As Object, e As EventArgs)
      newProgressBar1.Style = ProgressBarStyle.Blocks
      If newProgressBar1.Value < newProgressBar1.Maximum Then
       newProgressBar1.Value += 10
      End If
     End Sub
    End Class
    
    Public Class NewProgressBar
     Inherits ProgressBar
     Public Property Percentage() As Integer
      Get
       Return m_Percentage
      End Get
      Set(value As Integer)
       m_Percentage = value
      End Set
     End Property
     Private m_Percentage As Integer
     Public Property ShowText() As Boolean
      Get
       Return m_ShowText
      End Get
      Set(value As Boolean)
       m_ShowText = value
      End Set
     End Property
     Private m_ShowText As Boolean
    
     Public Property Color1() As Color
      Get
       Return m_Color1
      End Get
      Set(value As Color)
       m_Color1 = value
      End Set
     End Property
     Private m_Color1 As Color
     Public Property Color2() As Color
      Get
       Return m_Color2
      End Get
      Set(value As Color)
       m_Color2 = value
      End Set
     End Property
     Private m_Color2 As Color
     Public Property Color3() As Color
      Get
       Return m_Color3
      End Get
      Set(value As Color)
       m_Color3 = value
      End Set
     End Property
     Private m_Color3 As Color
    
     Public Property Position1() As Single
      Get
       Return m_Position1
      End Get
      Set(value As Single)
       m_Position1 = value
      End Set
     End Property
     Private m_Position1 As Single
     Public Property Position2() As Single
      Get
       Return m_Position2
      End Get
      Set(value As Single)
       m_Position2 = value
      End Set
     End Property
     Private m_Position2 As Single
     Public Property Position3() As Single
      Get
       Return m_Position3
      End Get
      Set(value As Single)
       m_Position3 = value
      End Set
     End Property
     Private m_Position3 As Single
    
     Private t As New Timer()
     Private _rec As RectangleF
    
     Private _marqueeWidth As Single = 0
     Public Property MarqueeWidth() As Single
      Get
       Return _marqueeWidth
      End Get
      Set(value As Single)
       _marqueeWidth = value
       If Me.MarqueeWidth > 0 Then
        _rec = New RectangleF(-Me.MarqueeWidth, 0, Me.MarqueeWidth, Me.ClientSize.Height)
       End If
      End Set
     End Property
    
     Private _style As ProgressBarStyle = ProgressBarStyle.Blocks
     Public Shadows Property Style() As ProgressBarStyle
      Get
       Return _style
      End Get
      Set(value As ProgressBarStyle)
       _style = value
       If _style = ProgressBarStyle.Marquee Then
        If Me.MarqueeWidth > 0 Then
         _rec = New RectangleF(-Me.MarqueeWidth, 0, Me.MarqueeWidth, Me.ClientSize.Height)
        End If
        t.Start()
       Else
        t.[Stop]()
       End If
      End Set
     End Property
    
     Private _marqueeAnimationSpeed As Integer = 100
     Public Shadows Property MarqueeAnimationSpeed() As Integer
      Get
       Return _marqueeAnimationSpeed
      End Get
      Set(value As Integer)
       _marqueeAnimationSpeed = value
       t.Interval = _marqueeAnimationSpeed
      End Set
     End Property
    
     Public Property MarqueeIncrement() As Integer
      Get
       Return m_MarqueeIncrement
      End Get
      Set(value As Integer)
       m_MarqueeIncrement = value
      End Set
     End Property
     Private m_MarqueeIncrement As Integer
    
     Public Shadows Property Value() As Integer
      Get
       Return Me.Percentage
      End Get
      Set(value As Integer)
       Me.Percentage = value
       Me.Invalidate()
      End Set
     End Property
    
     Public Property DrawBlendShadow() As Boolean
      Get
       Return m_DrawBlendShadow
      End Get
      Set(value As Boolean)
       m_DrawBlendShadow = value
      End Set
     End Property
     Private m_DrawBlendShadow As Boolean
    
     Public Sub New()
      Me.SetStyle(ControlStyles.UserPaint, True)
      Me.DoubleBuffered = True
      Me.Color1 = Color.Lime
      Me.Color2 = Color.Green
      Me.Color3 = Color.Red
      Me.Position1 = 0
      Me.Position2 = 0.55F
      Me.Position3 = 1.0F
      Me.MarqueeIncrement = 5
      Me.DrawBlendShadow = True
      _rec = New RectangleF(-Me.ClientSize.Width / 4.0F, 0, Me.ClientSize.Width / 4.0F, Me.ClientSize.Height)
      t.Interval = Me.MarqueeAnimationSpeed
      AddHandler t.Tick, AddressOf t_Tick
     End Sub
    
     Private Sub t_Tick(sender As Object, e As EventArgs)
      _rec = New RectangleF(_rec.X + Me.MarqueeIncrement, _rec.Y, _rec.Width, _rec.Height)
    
      If _rec.X > Me.ClientSize.Width + _rec.Width Then
       _rec.X = -_rec.Width
      End If
    
      Me.Invalidate()
     End Sub
    
     Protected Overrides Sub OnPaint(e As PaintEventArgs)
      Dim rec As Rectangle = e.ClipRectangle
    
      rec.Width = CInt(rec.Width * (CDbl(Value) / Maximum)) - 4
    
      If ProgressBarRenderer.IsSupported Then
       ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle)
      Else
       e.Graphics.DrawRectangle(Pens.Gray, 0, 0, Me.Width, Me.Height)
      End If
    
      rec.Height = rec.Height - 4
    
      If Me.Style <> ProgressBarStyle.Marquee Then
       Using l As New System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.Green, Color.Red, 0.0F)
        Dim lb As New System.Drawing.Drawing2D.ColorBlend()
        lb.Colors = New Color() {Color1, Color2, Color3}
        lb.Positions = New Single() {Position1, Position2, Position3}
        l.InterpolationColors = lb
    
        e.Graphics.FillRectangle(l, 2, 2, rec.Width, rec.Height)
       End Using
    
       Using l2 As New System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, Color.FromArgb(147, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), System.Drawing.Drawing2D.LinearGradientMode.Vertical)
        Dim lb As New System.Drawing.Drawing2D.ColorBlend()
        lb.Colors = New Color() {Color.FromArgb(40, 255, 255, 255), Color.FromArgb(147, 255, 255, 255), Color.FromArgb(40, 255, 255, 255), Color.FromArgb(0, 255, 255, 255)}
        lb.Positions = New Single() {0, 0.12F, 0.39F, 1.0F}
        l2.InterpolationColors = lb
    
        l2.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile
        e.Graphics.FillRectangle(l2, 2, 2, rec.Width, rec.Height)
       End Using
    
       If Me.ShowText Then
        Using sb As New SolidBrush(Me.ForeColor)
         Dim sz As SizeF = e.Graphics.MeasureString(Percentage.ToString() + " %", Me.Font)
         e.Graphics.DrawString(Percentage.ToString() + " %", Me.Font, sb, New PointF((Me.Width - sz.Width) / 2.0F, (Me.Height - sz.Height) / 2.0F))
        End Using
       End If
      Else
       Using l As New System.Drawing.Drawing2D.LinearGradientBrush(_rec, Color.Green, Color.Red, 0.0F)
        Dim lb As New System.Drawing.Drawing2D.ColorBlend()
        lb.Colors = New Color() {Color1, Color2, Color3}
        lb.Positions = New Single() {Position1, Position2, Position3}
        l.InterpolationColors = lb
    
        e.Graphics.FillRectangle(l, _rec)
       End Using
    
       If DrawBlendShadow Then
        Using l2 As New System.Drawing.Drawing2D.LinearGradientBrush(_rec, Color.FromArgb(147, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), System.Drawing.Drawing2D.LinearGradientMode.Vertical)
         Dim lb As New System.Drawing.Drawing2D.ColorBlend()
         lb.Colors = New Color() {Color.FromArgb(40, 255, 255, 255), Color.FromArgb(147, 255, 255, 255), Color.FromArgb(40, 255, 255, 255), Color.FromArgb(0, 255, 255, 255)}
         lb.Positions = New Single() {0, 0.12F, 0.39F, 1.0F}
         l2.InterpolationColors = lb
    
         l2.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile
         e.Graphics.FillRectangle(l2, _rec)
        End Using
       End If
      End If
     End Sub
    
     Protected Overrides Sub Dispose(disposing As Boolean)
      t.Dispose()
    
      MyBase.Dispose(disposing)
     End Sub
    End Class
    
    
    
    

    Regards,

      Thorsten

    ------------------------ Perfect It solved my issue, Thank you very much.
    N.A.Malik
    Tuesday, June 07, 2011 6:38 PM
  • the simple way is 

    progressBar1.ForeColor = Color.FromArgb(255, 0, 0);

     or

    progressBar1.ForeColor = Color.Red;

    and comment the line in program.cs as

    // Application.EnableVisualStyles();

    Sunday, February 16, 2014 8:02 AM