-
Notifications
You must be signed in to change notification settings - Fork 60
/
ProgressBar.cs
47 lines (38 loc) · 1.69 KB
/
ProgressBar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace CurePlease
{
public class NewProgressBar : ProgressBar
{
public NewProgressBar ()
{
SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaintBackground (PaintEventArgs pevent)
{
// None... Helps control the flicker.
}
protected override void OnPaint (PaintEventArgs e)
{
const int inset = 1; // A single inset value to control the sizing of the inner rect.
using (Image offscreenImage = new Bitmap(Width, Height))
{
using (Graphics offscreen = Graphics.FromImage(offscreenImage))
{
Rectangle rect = new Rectangle(0, 0, Width, Height);
if (ProgressBarRenderer.IsSupported)
ProgressBarRenderer.DrawHorizontalBar(offscreen, rect);
rect.Inflate(new Size(-inset, -inset)); // Deflate inner rect.
rect.Width = (int)( rect.Width * ( (double)Value / Maximum ) );
if (rect.Width == 0) rect.Width = 1; // Can't draw rec with width of 0.
LinearGradientBrush brush = new LinearGradientBrush(rect, BackColor, ForeColor, LinearGradientMode.Vertical);
offscreen.FillRectangle(brush, inset, inset, rect.Width, rect.Height);
e.Graphics.DrawImage(offscreenImage, 0, 0);
offscreenImage.Dispose();
}
}
}
}
}
// Source: http://stackoverflow.com/questions/778678/how-to-change-the-color-of-progressbar-in-c-sharp-net-3-5