如何在 C# .NET 3.5 中更改进度条的颜色? [英] How to change the color of progressbar in C# .NET 3.5?

查看:55
本文介绍了如何在 C# .NET 3.5 中更改进度条的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的进度条上做两件事.

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

  1. 将绿色更改为红色.
  2. 移除积木并使其变成一种颜色.

关于我想知道如何完成的这两件事的任何信息都将非常感谢!

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

谢谢.

推荐答案

因为前面的答案似乎不适用于 Visual Styles.您可能需要创建自己的类或扩展进度条:

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);
    }
}

更新代码使进度条使用背景视觉样式

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

这篇关于如何在 C# .NET 3.5 中更改进度条的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆