有没有可能禁用进度条的动画效果?
我需要禁用它,因为某些过程已经暂停,此时如果进度条一直闪烁,普通用户会认为该过程正在运行。
建议创建自己的进度条控件并不是我想要的。
有没有可能禁用进度条的动画效果?
我需要禁用它,因为某些过程已经暂停,此时如果进度条一直闪烁,普通用户会认为该过程正在运行。
建议创建自己的进度条控件并不是我想要的。
// Assuming a Form1 with 3 ProgressBar controls
private void Form1_Load(object sender, EventArgs e)
{
SendMessage(progressBar2.Handle,
0x400 + 16, //WM_USER + PBM_SETSTATE
0x0003, //PBST_PAUSED
0);
SendMessage(progressBar3.Handle,
0x400 + 16, //WM_USER + PBM_SETSTATE
0x0002, //PBST_ERROR
0);
}
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern uint SendMessage(IntPtr hWnd,
uint Msg,
uint wParam,
uint lParam);
向用户传达某个动作已暂停或无法准确测量的标准方式是使用跑马灯显示样式。
progressBar1.Style = ProgressBarStyle.Marquee;
这种样式忽略了Maximum
和Value
属性,显示了一个进度条“段”,该段不断地在进度条上移动并循环(它不会填充进度条,而是将看起来像一部分进度条的东西移动到控件的整个范围内,然后再回到开头。)
public class my_progress_bar : ProgressBar {
public Brush brush;
public my_progress_bar() {
this.SetStyle(ControlStyles.UserPaint, true);
brush = Brushes.ForestGreen;
}
protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint(e);
Rectangle rectangle = e.ClipRectangle;
rectangle.Width = (int)(rectangle.Width * ((double)Value / Maximum)) - 4;
ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
rectangle.Height = Height - 4;
e.Graphics.FillRectangle(brush, 2, 2, rectangle.Width, rectangle.Height);
}
}
e.ClipRectangle
;这样渲染不正确。此外,你需要一个Vista风格的进度条。调用 ProgressBarRenderer.DrawHorizontalChunks
会让它看起来更好一些。 - SLakse.ClipRectangle
是需要重新绘制的区域。您应该使用 this.ClientRectangle
。 - SLaks将此粘贴为代码。这将重写进度条,也可以自定义颜色。
public class CProgressBar : ProgressBar
{
public Color MyColor {
get { return _color; }
set {
_color = value;
MyBrush = new SolidBrush(_color);
Invalidate();
}
}
private Color _color = Color.Green;
public CProgressBar()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
}
public int Value {
get { return _value; }
set {
_value = value;
Invalidate();
}
}
private int _value;
private SolidBrush MyBrush = new SolidBrush(_color);
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(MyBrush, new Rectangle(0, 0, Width * (_value / Maximum), Height));
}
}