Click here to Skip to main content
15,890,282 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.6K   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

 
GeneralMy vote of 5 Pin
NTDLS2-Mar-22 6:49
NTDLS2-Mar-22 6:49 
QuestionFrom Top or Bottom Pin
tito.gnap31-Aug-16 3:33
tito.gnap31-Aug-16 3:33 
GeneralVisual Styles Pin
Member 1023631813-Jun-16 7:23
Member 1023631813-Jun-16 7:23 
Generalappreciated Pin
Member 1041477627-Dec-13 23:39
Member 1041477627-Dec-13 23:39 
QuestionVerticalProgressBar does not appear in the toolbox Pin
petrus bitbyter17-Apr-12 3:13
petrus bitbyter17-Apr-12 3:13 
GeneralMy vote of 5 Pin
John Smith Becera18-Oct-10 22:48
John Smith Becera18-Oct-10 22:48 
GeneralTop Down Progress [modified] Pin
Hamsterhead200123-Mar-08 17:14
Hamsterhead200123-Mar-08 17:14 
JokeRe: Top Down Progress Pin
Ingenious00117-Jun-08 23:39
Ingenious00117-Jun-08 23:39 
GeneralNice Pin
Paul Conrad4-Nov-07 7:50
professionalPaul Conrad4-Nov-07 7:50 
GeneralVisualStyles Pin
The_Mega_ZZTer2-Nov-07 9:55
The_Mega_ZZTer2-Nov-07 9:55 
Since you've ported it to .NET 2.0 you might want to look into the System.VisualStyles namespace, which provides tools to render controls in XP/Vista VisualStyles (when they are in use).

Your "classic" vertical progressbar would look out of place on a form with XP/Vista styled controls. Fortunately it does not take much work to do this... most of it is easy enough to guess with intellisense.

Basically you find a VisualStyleElement you want to draw using Intellisense, then make a new VisualStyleRenderer from it (pass the static VSE item in as an argument to the constructor) then you DrawBackground it over the area you want to paint. For the progressbar background you'd just specify the whole control bounds, although you might want to draw it horizontally onto a bitmap first, then rotate the bitmap and blit it onto your control for a proper vertical look.

VSRs also provide stuff like margins and padding information which would be helpful in positioning the bars inside this background.

Custom colored bars would be difficult, but you could experiment with hue/saturation shifting the graphic of the bars. Or you could just draw your own "classic" bars as normal on top of the themed background (and have another boolean option for themed bars maybe).

I hope you find my suggestions helpful. Just remember that all calls to VisualStyles stuff will fail if VisualStyles are not enabled by the user (you can check in VisualStylesInformation.IsUserEnabled... IsOSSupported isn't as important to check). In these cases you could simply draw the control as it's being drawn now.
GeneralUpdated Pin
Jiajun Lu2-Nov-07 3:06
Jiajun Lu2-Nov-07 3:06 
GeneralRe: Updated Pin
Member 61050225-Jun-09 20:03
Member 61050225-Jun-09 20:03 
GeneralDerive from Control, not UserControl Pin
Sergey Alexandrovich Kryukov23-Oct-07 6:42
mvaSergey Alexandrovich Kryukov23-Oct-07 6:42 
GeneralRe: Derive from Control, not UserControl Pin
NormDroid2-Nov-07 1:49
professionalNormDroid2-Nov-07 1:49 
GeneralRe: Derive from Control, not UserControl Pin
The_Mega_ZZTer2-Nov-07 9:48
The_Mega_ZZTer2-Nov-07 9:48 
GeneralRe: Derive from Control, not UserControl Pin
NormDroid4-Nov-07 20:36
professionalNormDroid4-Nov-07 20:36 
GeneralRe: Derive from Control, not UserControl Pin
#realJSOP25-Nov-07 2:57
mve#realJSOP25-Nov-07 2:57 
Questionhow we differentiate word dll version Pin
ram on c#11-Jun-07 21:41
ram on c#11-Jun-07 21:41 
QuestionMultiple Color Pin
Reza Shojaee14-May-07 2:34
Reza Shojaee14-May-07 2:34 
AnswerRe: Multiple Color Pin
Jiajun Lu2-Nov-07 3:09
Jiajun Lu2-Nov-07 3:09 
QuestionCan I use it on VB .net? Pin
TheSilentman13-Feb-07 17:06
TheSilentman13-Feb-07 17:06 
AnswerRe: Can I use it on VB .net? Pin
Paul Conrad4-Nov-07 7:49
professionalPaul Conrad4-Nov-07 7:49 
GeneralWindows Vertical Progressbar Pin
reflex@codeproject24-Sep-06 13:49
reflex@codeproject24-Sep-06 13:49 
AnswerRe: Windows Vertical Progressbar Pin
GLMnet2-Aug-07 9:31
GLMnet2-Aug-07 9:31 
GeneralMin. > 0 Pin
keith.h14-Sep-06 21:23
keith.h14-Sep-06 21:23 

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.