如何改变进度的C#.NET 3.5的颜色?进度、颜色、NET

2023-09-02 01:22:25 作者:滚,不配和哥玩

我想要做的两件事情对我的进步吧。

I'd like to do two things on my progress bar.

更改绿色变为红色。 删除块,使之成为一种颜色。

有关这两件事我不知道如何做到将greatfuly AP preaciated任何信息!

Any information about those two things I wonder how to accomplish will be greatfuly appreaciated!

感谢。

推荐答案

由于previous答案似乎不工作,在视觉样式。您可能需要创建自己的类或延长进度条:

Since the previous answers don't appear to work in with Visual Styles. You'll probably need to create your own class or extend the progress bar:

public class NewProgressBar : ProgressBar
{
    public NewProgressBar()
    {
        this.SetStyle(ControlStyles.UserPaint, true);
    }

    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);
        rec.Height = rec.Height - 4;
        e.Graphics.FillRectangle(Brushes.Red, 2, 2, rec.Width, rec.Height);
    }
}

编辑:更新code键使进度条使用视觉样式背景

Updated code to make the progress bar use the visual style for the background