Files
1258/JinYuan.ControlLib/FanShapedSchedule.cs
T

89 lines
2.9 KiB
C#
Raw Normal View History

2026-08-04 18:36:40 +08:00
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace JinYuan.ControlLib
{
public partial class FanShapedSchedule : UserControl
{
public FanShapedSchedule()
{
InitializeComponent();
}
//最大值
private float maxValue = 100;
[Browsable(true)]//是否可见
[Category("自定义属性")] //类别
[Description("设置最大值")]
public float MaxValue
{
get { return maxValue; }
set
{
maxValue = value;
this.Invalidate();
}
}
//实际值
private float actureValue = 60;
[Browsable(true)]//是否可见
[Category("自定义属性")] //类别
[Description("设置实际值")]
public float ActureValue
{
get { return actureValue; }
set
{
actureValue = value;
this.Invalidate();
}
}
//文字显示值
private float PercentVal = 0;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// 获取画布
Graphics graphics = e.Graphics;
//消除锯齿
graphics.SmoothingMode = SmoothingMode.AntiAlias;
//文字显示效果
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
//插补模式
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
//图片呈现质量
graphics.CompositingQuality = CompositingQuality.HighQuality;
// 绘制底圆
SolidBrush brush1 = new SolidBrush(Color.FromArgb(93, 107, 153));
Rectangle rectangle1 = new Rectangle(1, 1, this.Width - 2, this.Height - 2);
graphics.FillEllipse(brush1, rectangle1);
//绘制扇形
Rectangle rectangle2 = new Rectangle(1, 1, this.Width - 2, this.Height - 2);
LinearGradientBrush brush2 = new LinearGradientBrush(rectangle2, Color.Blue, Color.Red, 150.0f, true);
this.PercentVal = (ActureValue / MaxValue) * 100;
graphics.FillPie(brush2, rectangle2, -90, (ActureValue / MaxValue) * 360f);
//绘制上圆
SolidBrush solidBrushElipse = new SolidBrush(this.BackColor);
Rectangle rectangle3 = new Rectangle(15, 15, this.Width - 30, this.Height - 30);
graphics.FillEllipse(solidBrushElipse, rectangle3);
//绘制文字
Font font = new Font("微软雅黑", 15);
PointF point = new PointF(((float)this.Width) / 2.0f - 27, ((float)this.Height) / 2.0f - 10);
graphics.DrawString(this.PercentVal.ToString("0.0") + "%", font, Brushes.Coral, point);
}
}
}