protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect = this.ClientRectangle;
float percent = (val - min) / (float)(max - min);
// calculate area for drawing the progress
var t = (int)(rect.Height * percent);
rect.Height = t;
rect.Y = this.ClientRectangle.Height - t;
// draw the progress meter
using (var brush = new SolidBrush(barColor))
{
g.FillRectangle(brush, rect);
}
// draw red bar
if (val == 100)
{
using (var redBrush = new SolidBrush(Color.DeepPink))
{
g.FillRectangle(redBrush, 0, 0, ClientRectangle.Width, 2);
}
}
g.Dispose();
}