Click here to Skip to main content
12,943,299 members (74,876 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 27 May 2005

ProgressPieControl: an alternative to that [ boring :) ] ProgressBar

, 27 May 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
A custom progress control, using graphics and double buffering.

Sample Image - ProgressPieControl.jpg


Well, I guess it happens to everyone (normally constituted ^_^) to be bored of those controls, specially the progress bar.

That fatal thing occurred to me last month, while I was doing some coding... I decided to create my own progress bar with no bars, after I searched for a substitute over the users' contributions in CodeProject.


Actually, the ProgressPie uses some basic trigonometry, but do not worry, everything is easy to learn since you want to...

Using the control

Just like every control, you just have to make a reference to the library file, add it to your ToolBox (at this time ProgressPie has no ToolBox bitmap, I'm looking for one), and fill in its properties which are:

  • Comment: the text you want to see inside ProgressPie.
  • Maximum: the maximum value of ProgressPie.
  • Minimum: the minimum value of ProgressPie.
  • Value: its start value.

After you have inserted the ProgressPie control, just modify its value programmatically. In the demo code, I used a timer to make its value change at the timer's interval.

Using the ProgressPie source

The ProgressPie class contains some getters and setters, which makes it possible to access its comment, maximum, minimum and value. Some attributes are set using:

[Category("Appearance"),Description("The Maximal value of the ProgessPie.")]

But basically it overrides the OnPaint event to do some other drawing:

protected override void OnPaint(PaintEventArgs e)
    Graphics gr = e.Graphics; //get the graphics from the PaintEvent
    int nAngle = (int) Math.Floor ( (float) (nValue - nMinimum) / 
        (float) (nMaximum - nMinimum) * 360F);
        //convert from current value to degrees Angle
    SolidBrush redBrush = new SolidBrush(Color.Red);
    Rectangle rg = new Rectangle(this.Left - this.Location.X ,
        this.Top - this.Location.Y,this.Size.Width,this.Size.Width);
    GraphicsPath pthToDraw = new GraphicsPath();
    PointF[] ptsArray = pthToDraw.PathPoints;
    PathGradientBrush pgBrush = new PathGradientBrush(ptsArray);
    //while less than alret value, draw in Green else in Red
    if (nValue < (int) Math.Floor( (double) 
                      (fAlert / 100 * ( nMaximum - nMinimum))) )
        pgBrush.CenterColor = Color.Green;         
        pgBrush.CenterColor = Color.Red;
    Color[] srColor = {Color.Blue};
    pgBrush.SurroundColors = srColor;
    PointF ptCenter = new PointF( (float)(this.Left - 
                      this.Location.X + this.Size.Width / 2F ),
        (float)(this.Top - this.Location.Y + this.Size.Height / 2F ) );
    int nRay = this.Width / 2;
    double PiAngle = nAngle * Math.PI / 180 ;
    pgBrush.CenterPoint = new PointF (
            (float) ptCenter.X + nRay * (float)Math.Cos(PiAngle),
            (float) ptCenter.Y + nRay * (float)Math.Sin(PiAngle));
    base.OnPaint (e);

If you find that the ProgressPie doesn't act just like you wish, or isn't just enough colorized, you just have to modify the OnPaint override, to be fully satisfied :). Anyway, the ProgressPie uses double buffering, which is accessible using the portion of code below, which makes it smoother in high frame rates:

this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);


Any comment would be very helpful :)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chief Technology Officer
Morocco Morocco
in his studies, erratum discovered c/c++.he appreciated it.
when he met oracle products, in his job, he fell in love.
he uses c# .net & ms sql.

he created a "f.r.i.e.n.d.s" like soap movie, melting all of the above.
went back in the university.
after he took courses of artificial vision & imagery, he finished his studies with a successful license plate recognition project.

You may also be interested in...

Comments and Discussions

GeneralFlicker Pin
fwsouthern3-Jun-05 11:17
memberfwsouthern3-Jun-05 11:17 
GeneralRe: Flicker Pin
eRRaTuM5-Jun-05 23:23
membereRRaTuM5-Jun-05 23:23 
Generallooks great keep up the good work Pin
Gil_Schmidt30-May-05 12:10
memberGil_Schmidt30-May-05 12:10 
GeneralRe: looks great keep up the good work Pin
eRRaTuM30-May-05 23:34
membereRRaTuM30-May-05 23:34 
GeneralRe: looks great keep up the good work Pin
Gil_Schmidt30-May-05 23:47
memberGil_Schmidt30-May-05 23:47 
GeneralRe: looks great keep up the good work Pin
eRRaTuM31-May-05 0:43
membereRRaTuM31-May-05 0:43 
GeneralRe: looks great keep up the good work Pin
Gil_Schmidt31-May-05 19:14
memberGil_Schmidt31-May-05 19:14 
GeneralRe: looks great keep up the good work Pin
eRRaTuM1-Jun-05 6:06
membereRRaTuM1-Jun-05 6:06 
GeneralMissing zip files Pin
minja27-May-05 11:23
memberminja27-May-05 11:23 
GeneralRe: Missing zip files Pin
eRRaTuM30-May-05 0:30
membereRRaTuM30-May-05 0:30 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170518.1 | Last Updated 27 May 2005
Article Copyright 2005 by eRRaTuM
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid