Disable WinForms ProgressBar animation

后端 未结 6 1794
温柔的废话
温柔的废话 2020-12-03 22:03

Is there a possbility to disable animation of the progress bar?

I need it for some pocess which is paused and not running at the moment. An average user would think

6条回答
  •  独厮守ぢ
    2020-12-03 22:22

    You could override the OnPaint() of the progressbar. You don't actually need to rewrite the whole thing, you just have to inherit the progressbar and override OnPaint like this:

    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);
            }
        }
    

提交回复
热议问题