是否有禁用进度条动画的可能性?禁用WinForms ProgressBar动画
我需要它的一些暂停,并没有运行的时刻。如果进度条闪烁,普通用户会认为该进程正在运行。
创建自己的进度条控件的建议不是我正在寻找的。
是否有禁用进度条动画的可能性?禁用WinForms ProgressBar动画
我需要它的一些暂停,并没有运行的时刻。如果进度条闪烁,普通用户会认为该进程正在运行。
创建自己的进度条控件的建议不是我正在寻找的。
可以使用Vista的进度条的暂停状态,like this:
// 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
性能和显示进度条“段”,不断跨越的进度条移动和周围循环(它不填充进度条,它的动作是什么样子节横跨控件并重新开始。)
谢谢。但我需要MAximum和Value。用户需要查看进程暂停的位置。 – 2010-05-14 14:32:27
@Vasily:这是唯一的与操作系统无关的过程;如果你保证Vista或7,那么SLak的答案应该可以解决你的问题。 – 2010-05-14 15:06:58
您要做的就是在此控件上专门设置样式以覆盖主题更改。这article给你一些信息。
http://www.codeproject.com/KB/cpp/ExtendedProgressbar.aspx看起来不错。但我怀疑我的老板会批准非标准的外观控制。 – 2010-05-14 14:35:49
您可以覆盖进度的OnPaint()方法。您实际上并不需要重写整个事情,只需继承进度条并像这样覆盖OnPaint:
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);
}
}
将此代码粘贴到代码中。这将重写进度条,它也可以通过颜色进行自定义。
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));
}
}
顺便说一句,它的工作。如果有人把这个数字计算在内,这意味着他太便宜,无法亲自尝试。 – ad48 2016-12-27 21:32:56
我觉得你,只是倒下而已,甚至没有说出原因。尽管在使用.Net 4.5时代码存在很多问题:类需要是部分的,MyBrush不能用非静态值初始化,最后也没有任何内容被绘制。我错了什么? – 2017-05-12 23:20:15
由于int转换,宽度*(_value/Maximum)始终为零。 – 2017-05-12 23:28:11
你说的是Vista的图形效果吗?一个帐篷酒吧? – SLaks 2010-05-14 14:13:14
是的。 XP,Vista和W7的影响。 – 2010-05-14 14:14:19
这可能是相关的https://social.msdn.microsoft.com/Forums/vstudio/en-US/d223204c-24ab-4ca5-bb45-1400e3af2922/is-there-a-progress-bar-alternative-available-from -uuget-for-windows-7-that-sets-it-value-without?forum = csharpgeneral和http://stackoverflow.com/questions/37625930/cannot-get-progressbar-animation-with-code-progresschanged-not - 叫 – barlop 2016-06-04 22:36:21