改变系统自带进度条的方法就是重绘了。
具体方法如下:
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方法,按具体需要绘制控件外观。

本文介绍了如何通过重绘系统自带的ProgressBar控件来创建自定义的进度条效果。首先,你需要创建一个新的控件类,继承自ProgressBar,并设置ControlStyles.UserPaint为true。然后,重写OnPaint方法,在这里绘制进度条的背景和填充部分。通过调整bounds的宽度和高度,可以改变进度条的显示状态。这种方法允许开发者根据具体需求自由定制控件的外观。
1320

被折叠的 条评论
为什么被折叠?



