VerticalProgressBar.cs
1.3 KB
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
public class VerticalProgressBar : ProgressBar
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
//cp.Style |= 0x04;
cp.ExStyle |= 0x02000000;
return cp;
}
}
//===变为垂直显示方法1:
public VerticalProgressBar()
{
base.SetStyle(ControlStyles.UserPaint, true);
}
//重写OnPaint方法
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Rectangle rect = new Rectangle(base.ClientRectangle.Location, new Size(base.Width, base.Height));
ProgressBarRenderer.DrawVerticalBar(e.Graphics, rect);
//纯色填充
Brush lb = new SolidBrush(base.ForeColor);
var len = base.Height * base.Value / base.Maximum;
e.Graphics.FillRectangle(lb, new Rectangle(0, base.Height - len, base.Width, len));
Font font = new Font(FontFamily.GenericSansSerif, 10);
SolidBrush black = new SolidBrush(Color.Black);
e.Graphics.DrawString($"{Value}/{Maximum}", font, black, 0, 0);
}
}