145 lines
4.6 KiB
C#
145 lines
4.6 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using System.ComponentModel;
|
||
|
|
using System.Drawing;
|
||
|
|
using System.Drawing.Drawing2D;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Text;
|
||
|
|
using System.Windows.Forms;
|
||
|
|
|
||
|
|
namespace JYControl
|
||
|
|
{
|
||
|
|
public partial class CircleCountValue : Control
|
||
|
|
{
|
||
|
|
//这个写最上面是因为我自己也不懂是啥意思,只知道界面控件重绘容易产生闪烁的问题,这个加了就不会有
|
||
|
|
//解决控件批量更新时带来的闪烁
|
||
|
|
protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } }
|
||
|
|
|
||
|
|
//-------------------颜色
|
||
|
|
private Color bgColor = Color.FromArgb(224, 224, 224); //背景边框颜色
|
||
|
|
private Color sectorColor = Color.FromArgb(109, 179, 63); //扇形颜色
|
||
|
|
[Category("控件属性")]
|
||
|
|
[Description("背景边框颜色")]
|
||
|
|
public Color BgColor
|
||
|
|
{
|
||
|
|
get { return this.bgColor; }
|
||
|
|
set
|
||
|
|
{
|
||
|
|
this.bgColor = value;
|
||
|
|
this.Invalidate();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
[Category("控件属性")]
|
||
|
|
[Description("扇形颜色")]
|
||
|
|
public Color SectorColor
|
||
|
|
{
|
||
|
|
get { return this.sectorColor; }
|
||
|
|
set
|
||
|
|
{
|
||
|
|
this.sectorColor = value;
|
||
|
|
this.Invalidate();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private int borderWidth = 2;//边框宽度
|
||
|
|
[Category("控件属性")]
|
||
|
|
[Description("边框宽度")]
|
||
|
|
public int BorderWidth
|
||
|
|
{
|
||
|
|
get { return this.borderWidth; }
|
||
|
|
set
|
||
|
|
{
|
||
|
|
this.borderWidth = value;
|
||
|
|
this.Invalidate();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 圆形进度条实心
|
||
|
|
/// </summary>
|
||
|
|
public CircleCountValue()
|
||
|
|
{
|
||
|
|
InitControl();
|
||
|
|
this.SizeChanged += delegate
|
||
|
|
{
|
||
|
|
this.Invalidate(); //重绘控件
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
int maxValue = 500000; //进度最大值
|
||
|
|
private int countValue = 0;
|
||
|
|
/// <summary>
|
||
|
|
/// 进度值
|
||
|
|
/// </summary>
|
||
|
|
///
|
||
|
|
[Category("控件属性")]
|
||
|
|
[Description("进度值,最大值500000")]
|
||
|
|
public int CountValue
|
||
|
|
{
|
||
|
|
get { return this.countValue; }
|
||
|
|
set
|
||
|
|
{
|
||
|
|
if (value > this.maxValue)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.countValue = value;
|
||
|
|
this.Invalidate();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 初始化控件参数
|
||
|
|
/// </summary>
|
||
|
|
private void InitControl()
|
||
|
|
{
|
||
|
|
this.Width = 200;
|
||
|
|
this.Height = 200;
|
||
|
|
}
|
||
|
|
|
||
|
|
//对Control进行绘制
|
||
|
|
protected override void OnPaint(PaintEventArgs e)
|
||
|
|
{
|
||
|
|
DrawShape(e.Graphics); //绘制控件样式
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 画图
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="g">画图工具类</param>
|
||
|
|
private void DrawShape(Graphics g)
|
||
|
|
{
|
||
|
|
if (this.Width < borderWidth * 4 || this.Height < borderWidth * 4)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
g.SmoothingMode = SmoothingMode.AntiAlias; //消除锯齿,也就是抗锯齿什么鬼东西
|
||
|
|
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||
|
|
g.CompositingQuality = CompositingQuality.HighQuality;
|
||
|
|
|
||
|
|
|
||
|
|
RectangleF bg_rectangle = new RectangleF(0 + borderWidth, 0 + borderWidth, Width - borderWidth * 2, Height - borderWidth * 2); //控件整体坐标
|
||
|
|
|
||
|
|
g.DrawEllipse(new Pen(bgColor, borderWidth), bg_rectangle); //画背景圆
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
Rectangle rl = new Rectangle(0 + borderWidth * 2, 0 + borderWidth * 2, this.Width - borderWidth * 4, this.Height - borderWidth * 4);
|
||
|
|
|
||
|
|
decimal topAngle = (this.countValue * 1.0M / this.maxValue) * 360M;//计算进度条划过的度数
|
||
|
|
g.FillPie(new SolidBrush(sectorColor), rl, 0, (float)topAngle); //填充扇形
|
||
|
|
|
||
|
|
//SizeF proValSize = g.MeasureString(this.progress.ToString() + "%", this.Font);//计算文字的范围
|
||
|
|
SizeF proValSize = g.MeasureString(this.countValue.ToString(), this.Font);//计算文字的范围
|
||
|
|
|
||
|
|
//g.DrawString(this.progress.ToString() + "%", this.Font, new SolidBrush(this.ForeColor),
|
||
|
|
g.DrawString(this.countValue.ToString(), this.Font, new SolidBrush(this.ForeColor),
|
||
|
|
bg_rectangle.X + bg_rectangle.Width / 2 - proValSize.Width / 2, bg_rectangle.Y + bg_rectangle.Height / 2 - proValSize.Height / 2);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|