Disabling .NET progressbar animation when changing value?

There is another way to skip the animation of a vista-style progress bar: Just SetState() the control to PBST_PAUSED, then set the value and finally set it back to PBST_NORMAL.


Here is my extension method, based on David Heffernan's recommendation:

Wrap it up, hide it from view, and pretend it's not there!

public static class ExtensionMethods
{
    /// <summary>
    /// Sets the progress bar value, without using Windows Aero animation
    /// </summary>
    public static void SetProgressNoAnimation(this ProgressBar pb, int value)
    {
        // Don't redraw if nothing is changing.
        if (value == pb.Value)
            return;

        // To get around this animation, we need to move the progress bar backwards.
        if (value == pb.Maximum) {
            // Special case (can't set value > Maximum).
            pb.Value = value;           // Set the value
            pb.Value = value - 1;       // Move it backwards
        }
        else {
            pb.Value = value + 1;       // Move past
        }
        pb.Value = value;               // Move to correct value
    }
}

This animation feature was introduced in Vista with the Aero theme.

There is a workaround though. If you move the progress backwards, the animation is not shown. So if you want it to advance by 50 instantly, increment Value by 51, then immediately decrement by 1.

You get into strife when close to 100% because you can't set Value to 101 (I'm assuming Maximum is set to 100). Instead set Maximum to 1000, say, increase to 1000, decrease to 999, and then move back to 1000.

Anyway, it's kind of weird, but it does have the benefit of giving you the desired effect!