You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.7 KiB
66 lines
1.7 KiB
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace WindowsFormsApp1
|
|
{
|
|
internal class MyProcessBar : ProgressBar
|
|
{
|
|
|
|
private Color _foreColor = Color.Blue;
|
|
private Color _backColor = Color.White;
|
|
|
|
public MyProcessBar()
|
|
{
|
|
SetStyle(ControlStyles.UserPaint, true);
|
|
}
|
|
|
|
[System.ComponentModel.Category("Custom")]
|
|
public Color ForeColor
|
|
{
|
|
get { return _foreColor; }
|
|
set
|
|
{
|
|
_foreColor = value;
|
|
Invalidate();
|
|
}
|
|
}
|
|
|
|
[System.ComponentModel.Category("Custom")]
|
|
public Color BackColor
|
|
{
|
|
get { return _backColor; }
|
|
set
|
|
{
|
|
_backColor = value;
|
|
Invalidate();
|
|
}
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
base.OnPaint(e);
|
|
|
|
Rectangle rect = ClientRectangle;
|
|
rect.Width = (int)((double)rect.Width * (Value / (double)Maximum));
|
|
|
|
using (Brush backBrush = new SolidBrush(BackColor))
|
|
{
|
|
e.Graphics.FillRectangle(backBrush, rect);
|
|
}
|
|
|
|
using (Brush foreBrush = new SolidBrush(ForeColor))
|
|
{
|
|
rect.Width -= 1; // 为了避免绘制时超出边界,稍微减少宽度
|
|
e.Graphics.FillRectangle(foreBrush, new Rectangle(rect.Left + 1, rect.Top + 1, rect.Width - 1, rect.Height - 1));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|