简介:
圆盘进度条,按照百分比加载,可调节圆环颜色和扇形填充色。
属性总览:
M_LineColor:线颜色。
M_RgColor:扇形进度颜色。
M_Rate:进度百分比。最小0,最大100。
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UserDefineUI.MyDefineUI.ProgressBar
{
public partial class ProgressBarUser_Pie : UserControl
{
#region 属性
#region 线框颜色
private Color lineColor = Color.Black;
public Color M_LineColor
{
get
{
return lineColor;
}
set
{
lineColor = value;
}
}
#endregion
#region 进度颜色
private Color pgColor = Color.Gray;
public Color M_PgColor
{
get
{
return pgColor;
}
set
{
pgColor = value;
}
}
#endregion
#region 进度百分比
private float rate = 0;
public float M_Rate
{
get
{
return rate/3.6f;
}
set
{
if(value > 100)
{
rate = 360;
}
else if(rate < 0)
{
rate = 0;
}
else
{
rate = value * 3.6f;
}
Invalidate();
}
}
#endregion
#endregion
public ProgressBarUser_Pie()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
Graphics graphics = e.Graphics;
int w = Width;
int h = Height;
Point center = new Point(w / 2, h / 2);
int r = Width/2;
using (Pen pen = new Pen(lineColor))
{
pen.Width = 2;
graphics.DrawEllipse(pen, (center.X - r), (center.Y - r), 2*r-2, 2*r-2);
graphics.FillPie(new SolidBrush(pgColor), (float)(center.X - r), (float)(center .Y- r), 2 * r-2, 2 * r-2, 0, rate);
graphics.DrawPie(pen, w / 2 - r, h / 2-r, 2 * r - 2, 2 * r -2 , 0 , rate);
}
}
}
}
其他代码:
public partial class Form1 : Form
{
Timer time;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
time = new Timer();
time.Enabled = true;
time.Interval = 100;
time.Tick += TimerMainFormTick;
Task task = new Task(() =>
{
time.Start();
});
task.Start();
}
private void TimerMainFormTick(object sender, EventArgs e)
{
if (progressBarUser_Pie1.M_Rate == 100)
{
time.Stop();
}
progressBarUser_Pie1.M_Rate += 1;
}
}