如何在winforms上绘制我自己的进度条?

Yoyo专家! 我的Windowsform(不是WPF)上有几个进度条,我想为每个使用不同的颜色。 我怎样才能做到这一点? 我用Google搜索,发现我必须创建自己的控件。 但我不知道如何做到这一点。 任何的想法? 例如progressBar1绿色,progressbar2红色。

编辑:哦,我想解决这个问题,而不删除Application.EnableVisualStyles(); 线,因为它会抬起我的形状:/

是的,创建自己的。 一个粗略的草案,让你80%,根据需要修饰:

using System; using System.Drawing; using System.Windows.Forms; class MyProgressBar : Control { public MyProgressBar() { this.SetStyle(ControlStyles.ResizeRedraw, true); this.SetStyle(ControlStyles.Selectable, false); Maximum = 100; this.ForeColor = Color.Red; this.BackColor = Color.White; } public decimal Minimum { get; set; } // fix: call Invalidate in setter public decimal Maximum { get; set; } // fix as above private decimal mValue; public decimal Value { get { return mValue; } set { mValue = value; Invalidate(); } } protected override void OnPaint(PaintEventArgs e) { var rc = new RectangleF(0, 0, (float)(this.Width * (Value - Minimum) / Maximum), this.Height); using (var br = new SolidBrush(this.ForeColor)) { e.Graphics.FillRectangle(br, rc); } base.OnPaint(e); } }