Introduction
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.
Note
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;
int nAngle = (int) Math.Floor ( (float) (nValue - nMinimum) /
(float) (nMaximum - nMinimum) * 360F);
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();
pthToDraw.AddRectangle(rg);
PointF[] ptsArray = pthToDraw.PathPoints;
PathGradientBrush pgBrush = new PathGradientBrush(ptsArray);
if (nValue < (int) Math.Floor( (double)
(fAlert / 100 * ( nMaximum - nMinimum))) )
pgBrush.CenterColor = Color.Green;
else
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));
gr.FillPie(pgBrush,rg,0,nAngle);
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);
Finally
Any comment would be very helpful :)