'How can I obtain a vertical bar that fills, like a progress bar?

As the title says I'm trying to obtain a vertical a bar and fill it depending on values. I couldn't apply any answers I found. One answer suggested replacing System.Windows.Forms.ProgressBar with a class name but that renders my design view unusable. What can I do?

EDIT: I need a bar like that for somthing like a graph report showing how many ppl are at work from the total number of employes.



Solution 1:[1]

You can easily create a vertical progress bar control. Add a new class to your project and paste the code shown below. Compile and drop the new control from the top of the toolbox onto your form.

using System;
using System.Windows.Forms;

class VerticalProgressBar : ProgressBar {
    protected override CreateParams CreateParams {
        get {
            var cp = base.CreateParams;
            cp.Style |= 4;   // Turn on PBS_VERTICAL
            return cp;
        }
    }
}

If you want a more customized look then simply derive from Control instead, add a Value property, and override the OnPaint() method to draw it any way you like.

Solution 2:[2]

If you really want to implement your own control, you will find all you need in the System.Drawing namespace. Just use Rectangle objects (one frame and one progress). Fill the inner progress rectangle to show progress by manipulating its height via a value property.

If you don't know how to draw, check this out: How to: Create Graphics Objects for Drawing

Or just use the ProgressBarRenderer class to manipulate the frameworks progressbar your way. This class has a DrawVerticalBar() member. On MSDN you even find a complete example for a vertical bar, I think.

MSDN should be your first place to go when coding .NET apps and you need some basic how-to info.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hans Passant
Solution 2