Search code examples
c#winformssharpdevelop

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

  • 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.