13

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 the process is running if the progress bar is being blinking.

The advice to create own progress bar control is not what I'm looking for.

Vasyl Boroviak
  • 5,959
  • 5
  • 51
  • 70
  • 1
    Are you talking about Vista's graphical effect? A marquee bar? – SLaks May 14 '10 at 14:13
  • Yes. XP, Vista and W7 effect. – Vasyl Boroviak May 14 '10 at 14:14
  • this may be relevant https://social.msdn.microsoft.com/Forums/vstudio/en-US/d223204c-24ab-4ca5-bb45-1400e3af2922/is-there-a-progress-bar-alternative-available-from-nuget-for-windows-7-that-sets-it-value-without?forum=csharpgeneral and http://stackoverflow.com/questions/37625930/cannot-get-progressbar-animation-with-code-progresschanged-not-called – barlop Jun 04 '16 at 22:36
  • Possible duplicate of [Windows Forms ProgressBar: Easiest way to start/stop marquee?](https://stackoverflow.com/questions/312936/windows-forms-progressbar-easiest-way-to-start-stop-marquee) – Jim Fell Jul 10 '18 at 14:53
  • 1
    @JimFell thanks for voting this question to close. However, if you read carefully you'll find that these questions are totally different. See the accepted answer in both of them, please. – Vasyl Boroviak Jul 11 '18 at 00:56

6 Answers6

23

You can use the Vista progress bar's paused state, 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);
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    That's what I was looking for. Thank you. That project is great: http://windowsformsaero.codeplex.com/ – Vasyl Boroviak May 15 '10 at 06:33
  • Just ran into this same issue myself. One question though: would this solution also work for software that will run on XP, or is it Vista/Win7 exclusively? – Julian May 27 '10 at 15:24
  • Link leads to a missing page. Better to copy & paste relevant info in an answer. – dbkk Jun 02 '11 at 10:53
  • @SLaks Is there a way to get rid of the glow effect when it's green as well? – Isuru Nov 22 '15 at 13:43
4

My workaround was to use a Panel Control instead of ProgressBar. I changed BackColor, BorderStyle (to Fixed3D) and I manipulate its Width to display needed level of progress. I assumed that 100% of progress is equal to Width of the Form.

Panel as a ProgressBar

psur
  • 4,400
  • 26
  • 36
3

The standard means of communicating to a user that an action is either paused or can't be accurately measured is to use the marquee display style.

progressBar1.Style = ProgressBarStyle.Marquee;

This style ignores the Maximum and Value properties and displays a progress bar "segment" that continually moves across the progress bar and loops around (it doesn't fill the progress bar, it moves what looks like a section of the bar all the way across the control and around to the beginning again.)

Adam Robinson
  • 182,639
  • 35
  • 285
  • 343
0

What you will want to do is set the style on this control specifically to override the theme changes. This article gives you a bit of information.

Mitchel Sellers
  • 62,228
  • 14
  • 110
  • 173
  • http://www.codeproject.com/KB/cpp/ExtendedProgressbar.aspx looks good. But I doubt my boss would approve non-standard looking controls. – Vasyl Boroviak May 14 '10 at 14:35
-1

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);
        }
    }
Auxiliary
  • 2,687
  • 5
  • 37
  • 59
  • You're misunderstanding `e.ClipRectangle`; this will not render correctly. Also, you need a Vista-style bar. Calling `ProgressBarRenderer.DrawHorizontalChunks` will make it somewhat better. – SLaks May 14 '10 at 15:20
  • `e.ClipRectangle` is the area that needs to be repainted. You should use `this.ClientRectangle`. – SLaks May 14 '10 at 15:21
  • As I said in my question "The advice to create own progress bar control is not what I'm looking for." – Vasyl Boroviak May 15 '10 at 06:37
  • This answer is completely wrong. OnPaint() is never called in a progressbar because Progressbars are painted by Windows (UxTheme.dll) but not by the .NET framework. – Elmue Jun 18 '16 at 03:37
-2

Paste this as to code. This will rewrite the progress bar, it's also customizable to color.

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
  • 1
  • 1
  • Btw it's working. If someone count this down, it means he's too cheap to try it himself. – ad48 Dec 27 '16 at 21:32
  • I feel you, it is very rude to just downvote and not even say why. Although there are many issues with the code when using .Net 4.5: class needs to be partial, MyBrush cannot be initialized with non-static value, and nothing is painted in the end. What am I getting wrong? – Xan-Kun Clark-Davis May 12 '17 at 23:20
  • 1
    Width * (_value / Maximum) is always zero due to int conversion. – Xan-Kun Clark-Davis May 12 '17 at 23:28