question

weeweewe-3136 avatar image
0 Votes"
weeweewe-3136 asked ·

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

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

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



dotnet-csharp
po66m.png (3.1 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
1 Vote"
Castorix31 answered ·

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


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TimonYang-MSFT avatar image
1 Vote"
TimonYang-MSFT answered ·

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.png (7.5 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

jonny-8351 avatar image
0 Votes"
jonny-8351 answered ·
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.