How can I make a multi-colored segmented progress bar in C# Window From

wee weewe 1 Reputation point
2021-03-10T08:44:41.107+00:00

Here is a full working proposition of solution to the custom progress bar.

こちらのみたいですよろしくお願いいたします
76234-po66m.png

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,274 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Castorix31 81,741 Reputation points
    2021-03-10T09:22:07.1+00:00

    You can see : ColorBar - A Gradient Colored ProgressBar
    (VB, but same code in C#)

    1 person found this answer helpful.
    0 comments No comments

  2. Timon Yang-MSFT 9,576 Reputation points
    2021-03-11T02:34:22.647+00:00

    One way is to derive your own progressbar from the progressbar control, and then use PathGradientBrush or LinearGradientBrush to paint its color in the OnPaint method.

    An example using PathGradientBrush:

        public class MyProgressBar : ProgressBar  
        {  
            public MyProgressBar()  
            {  
                this.SetStyle(ControlStyles.UserPaint, true);  
            }  
      
            protected override void OnPaint(PaintEventArgs e)  
            {  
                Rectangle rec = e.ClipRectangle;  
                GraphicsPath path = new GraphicsPath();  
                path.AddRectangle(rec);  
      
                PathGradientBrush pthGrBrush = new PathGradientBrush(path);  
      
                pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255);  
      
                Color[] colors = { Color.Red,Color.Yellow};  
                pthGrBrush.SurroundColors = colors;  
      
                rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4;  
                if (ProgressBarRenderer.IsSupported)  
                    ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);  
                rec.Height = rec.Height - 4;  
                e.Graphics.FillRectangle(pthGrBrush, 2, 2, rec.Width, rec.Height);  
            }  
        }  
    

    76552-1.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  3. johnny8351 1 Reputation point
    2021-03-11T05:39:26.21+00:00
    0 comments No comments