forked from c0ldw1nter/echoes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModifiedProgressBar.cs
44 lines (41 loc) · 1.87 KB
/
ModifiedProgressBar.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using Echoes;
namespace ModifiedControls
{
public class ModifiedProgressBar : ProgressBar
{
public bool HasBorder = true;
public float BorderThickness = 1f;
public string Text = String.Empty;
public ModifiedProgressBar()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.DoubleBuffered = true;
}
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rec = e.ClipRectangle;
rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4;
if (ProgressBarRenderer.IsSupported) ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
rec.Height = rec.Height - 4;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
e.Graphics.FillRectangle(new SolidBrush(Program.mainWindow.volBarBackColor), 0, 0, Width, Height);
e.Graphics.FillRectangle(new SolidBrush(Program.mainWindow.volBarForeColor), 2, 2, rec.Width, rec.Height);
if (HasBorder) e.Graphics.DrawRectangle(new Pen(Program.mainWindow.volBarForeColor, BorderThickness), 0, 0, Width - BorderThickness, Height - BorderThickness);
if (String.IsNullOrWhiteSpace(Text)) return;
Font ft = new Font(Program.mainWindow.font2.FontFamily, rec.Height - 2, Program.mainWindow.font2.Style);
SizeF sz = e.Graphics.MeasureString(Text, ft);
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
e.Graphics.DrawString(Text, ft, Brushes.Black, new Rectangle(2, 2, Width, Height), sf);
}
}
}