是否有禁用進度條動畫的可能性?禁用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