改变系统自带进度条的方法就是重绘了。
具体方法如下:
1. 自定义控件继承自ProgressBar,如下:
public class CustomProgressBar : ProgressBar
{
public CustomProgressBar()
{
base.SetStyle(ControlStyles.UserPaint, true);
//...
}
//重写baiOnPaint方法
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush brush = null;
Pen pen;
Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
//...
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, bounds.Width - 2, bounds.Height - 2);
bounds.Height -= 4;
bounds.Width = ((int)(bounds.Width * (((double)base.Value) / ((double)base.Maximum)))) - 4;
brush = new SolidBrush(this.ForeColor);
e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);
}
}
2. 了解下ControlStyles枚举
3. 重绘控件
重写OnPaint方法,按具体需要绘制控件外观。