Click here to Skip to main content
15,890,845 members
Articles / Multimedia / GDI+
Article

Vertical ProgressBar

Rate me:
Please Sign up or sign in to vote.
4.44/5 (38 votes)
1 Nov 20071 min read 207.7K   10.9K   54   28
A vertical progressbar inherited from UserControl.

Sample Image - verticalprogressbar.jpg

Introduction

This is a very simple progress bar inherited from System.Windows.Forms.UserControl. The System.Windows.Forms.ProgressBar is only horizontal. And I cannot find a vertical version of a progress bar. I implemented this vertical progress bar with the same behavior as the horizontal progress bar. For my personal purpose, I provided this vertical progress bar with some enhanced features. First, the bar color can be changed by Color property. Second, the bar can be set to solid by setting Style property to Styles.Solid. The last feature is that the vertical progress bar can be borderless by setting BorderStyle property to BorderStyles.None.

Code

The code is very simple. The Styles and BorderStyles enums are defined as:

C#
public enum Styles
{
    Classic, // same as ProgressBar
    Solid
}
public enum BorderStyles
{
    Classic, // same as ProgressBar
    None
}

The VerticalProgressBar class is inherited from UserControl class. You can specify a particular image by using the ToolboxBitmapAttribute class. Here, I used the same image as the ProgressBar.

C#
[Description("Vertical Progress Bar")]
[ToolboxBitmap(typeof(ProgressBar))]
public sealed class VerticalProgressBar : System.Windows.Forms.UserControl
{
    ...    ...
}

For convenience, all of the vertical progress bar properties are organized into VerticalProgressBar category on the property window of Visual Studio .NET, using Category attribute.

C#
[Description( "VerticalProgressBar Maximum Value")]
[Category( "VerticalProgressBar" )]
[RefreshProperties(RefreshProperties.All)]
public int Maximum
{
    get
    {
    return m_Maximum;
    }
    set
    {
    m_Maximum = value;
    if(m_Maximum < m_Minimum)
            m_Minimum=m_Maximum;
        if(m_Maximum < m_Value)
                m_Value = m_Maximum;
        Invalidate();
    }
}

... ...

OnPaint function was overridden to draw bar and border if needed.

C#
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
    Graphics dc = e.Graphics;
    
    //Draw Bar
    drawBar(dc);

    //Draw Border
    drawBorder(dc);

    base.OnPaint(e);
}

Using the Code

To use this vertical progress bar, copy the VerticalProgressBar.dll under your project directory. Then choose Add/Remove Items.. on the context menu of toolbox pane, and select this file to add this control to the toolbox. It will show the same icon as the ProgressBar. Then you can use it as same as ProgressBar. The default properties of this vertical progress bar are set to the same as the ProgressBar. You can change Color, Style, and BorderStyle properties as you need.

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


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralInfinite Loop Pin
teeinep11-Jul-06 3:14
teeinep11-Jul-06 3:14 
Generalflickering Pin
moli13-Oct-04 5:11
moli13-Oct-04 5:11 
GeneralRe: flickering Pin
Anonymous13-Oct-04 6:04
Anonymous13-Oct-04 6:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.