Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

C# Progress Bar Status Bar Panel

0.00/5 (No votes)
30 Jun 2004 2  
A reusable progress bar panel control for display inside the status bar.

Progress Bar In Use

Introduction

You can't just drop a progress bar control into a status bar panel, so I made this. This is actually the second time I've had to do this, so I got fed up and wanted to drop the code here so nobody would have to do it again.

Using the code

First thing to do is just drop a status bar on your form, and create a Panel or two. You can mess around with the panel settings afterwards, but the easiest thing to do is select Owner-Draw on the status bar panel that you want to be the progress bar from the very beginning.

// Change the type of the panel to StatusBarProgressPanel on your Form

private StatusBarProgressPanel progressPanel;

// Initialize the measurement values

progressPanel.StartPoint = 0;
progressPanel.EndPoint = 100;
progressPanel.StepSize = 1;
progressPanel.ProgressPosition = 0;

Of course, once you change the type, you can change the properties using the Visual Studio Designer by simply clicking the "..." button of the Panel's property when the status bar is selected in the form designer. I've included some handy category attributes for Visual Studio's nifty reflection logic to pick up.

Properties Dialog from Status Bar in Form Designer

// Sample usage:


// progress the bar by one "step"

progressPanel.Step();

// reset the progress bar to the initial state

progressPanel.Reset();

// start/stop an infinite animation thread for the bar

// this is useful when you don't know how long something

// is going to take, or if the progress is just unmeasurable

progressPanel.StartAnimation();
progressPanel.StopAnimation();

// By default the value of the percentage of progress is displayed

// setting the "ShowText" property to false disables it

progressPanel.ShowText = false;

You may also change the AnimationStyle of the control. This basically controls the way the indicator is filled and emptied. The default is ProgressDisplayStyle.Infinate which is a pulsating draw style. Much cooler graphics can be used, just modify the Parent_DrawItem method.

/// <summary>

/// Statusbar Progress Display Styles

/// </summary>

public enum ProgressDisplayStyle
{
    /// <summary>

    /// A continually moving animation

    /// </summary>

    Infinite,
    /// <summary>

    /// A progress bar that fills from left to right

    /// </summary>

    LeftToRight,
    /// <summary>

    /// A progress bar that fills from right to left

    /// </summary>

    RightToLeft,
    /// <summary>

    /// A progress bar that fills from bottom to top

    /// </summary>

    BottomToTop,
    /// <summary>

    /// A progress bar that fills from top to bottom

    /// </summary>

    TopToBottom
}

History

  • 7/1/2004 - Initial revision.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here