SunnyUI/SunnyUI/Controls/UIRoundProcess.cs

202 lines
5.5 KiB
C#
Raw Normal View History

2021-04-08 23:10:53 +08:00
/******************************************************************************
* SunnyUI
2022-01-02 12:32:50 +08:00
* CopyRight (C) 2012-2022 ShenYongHua().
2021-04-08 23:10:53 +08:00
* QQ群56829229 QQ17612584 EMailSunnyUI@QQ.Com
*
* Blog: https://www.cnblogs.com/yhuse
* Gitee: https://gitee.com/yhuse/SunnyUI
* GitHub: https://github.com/yhuse/SunnyUI
*
* SunnyUI.dll can be used for free under the GPL-3.0 license.
* If you use this code, please keep this note.
* 使
******************************************************************************
* : UIRoundProcess.cs
* :
2022-01-05 21:57:47 +08:00
* : V3.1
2021-04-08 23:10:53 +08:00
* : 2021-04-08
*
* 2021-04-08: V3.0.2
* 2021-10-18: V3.0.8
2021-04-08 23:10:53 +08:00
******************************************************************************/
2021-04-09 17:39:28 +08:00
using System;
2021-04-08 23:10:53 +08:00
using System.ComponentModel;
using System.Drawing;
2021-04-09 17:39:28 +08:00
using System.Drawing.Drawing2D;
2021-04-08 23:10:53 +08:00
namespace Sunny.UI
{
/// <summary>
/// 圆形滚动条
/// </summary>
2021-04-09 17:39:28 +08:00
[ToolboxItem(true)]
[DefaultEvent("ValueChanged")]
[DefaultProperty("Value")]
2021-04-08 23:10:53 +08:00
public class UIRoundProcess : UIControl
{
public UIRoundProcess()
{
SetStyleFlags(true, false);
2021-04-08 23:10:53 +08:00
Size = new Size(120, 120);
Inner = 30;
Outer = 50;
2021-04-09 17:39:28 +08:00
fillColor = UIColor.Blue;
rectColor = Color.FromArgb(155, 200, 255);
foreColor = UIColor.Blue;
2021-04-08 23:10:53 +08:00
ShowText = false;
ShowRect = false;
}
[Description("显示文字小数位数"), Category("SunnyUI")]
[DefaultValue(1)]
public int DecimalPlaces
{
get => decimalCount;
set
{
decimalCount = Math.Max(value, 0);
Text = (posValue * 100.0 / maximum).ToString("F" + decimalCount) + "%";
}
}
private int decimalCount = 1;
2021-04-09 17:39:28 +08:00
private int maximum = 100;
2021-04-08 23:10:53 +08:00
2021-04-09 17:39:28 +08:00
[DefaultValue(100)]
[Description("最大值"), Category("SunnyUI")]
public int Maximum
{
get => maximum;
set
{
maximum = Math.Max(1, value);
Invalidate();
}
}
private int inner = 30;
private int outer = 50;
[Description("内径")]
[Category("SunnyUI")]
[DefaultValue(30)]
public int Inner
{
get => inner;
set
{
inner = Math.Max(value, 0);
Invalidate();
}
}
[Description("外径")]
[Category("SunnyUI")]
[DefaultValue(50)]
public int Outer
{
get => outer;
set
{
outer = Math.Max(value, 5);
Invalidate();
}
}
/// <summary>
/// 进度条前景色
/// </summary>
[Description("进度条前景色")]
[Category("SunnyUI")]
[DefaultValue(typeof(Color), "80, 160, 255")]
public Color ProcessColor
{
get => fillColor;
set => SetFillColor(value);
}
/// <summary>
/// 进度条背景色
/// </summary>
[Description("进度条背景色")]
[Category("SunnyUI")]
[DefaultValue(typeof(Color), "155, 200, 255")]
public Color ProcessBackColor
{
get => rectColor;
set => SetRectColor(value);
}
/// <summary>
/// 字体颜色
/// </summary>
[Description("字体颜色")]
[Category("SunnyUI")]
[DefaultValue(typeof(Color), "80, 160, 255")]
public override Color ForeColor
{
get => foreColor;
set => SetForeColor(value);
}
private int posValue;
[DefaultValue(0)]
[Description("当前位置"), Category("SunnyUI")]
public int Value
{
get => posValue;
set
{
2022-01-13 10:35:31 +08:00
value = Math.Max(value, 0);
value = Math.Min(value, maximum);
if (posValue != value)
{
posValue = value;
Text = (posValue * 100.0 / maximum).ToString("F" + decimalCount) + "%";
ValueChanged?.Invoke(this, posValue);
Invalidate();
}
2021-04-09 17:39:28 +08:00
}
}
public delegate void OnValueChanged(object sender, int value);
2021-04-08 23:10:53 +08:00
2021-04-09 17:39:28 +08:00
public event OnValueChanged ValueChanged;
2021-04-08 23:10:53 +08:00
2021-04-09 17:39:28 +08:00
protected override void OnPaintFill(Graphics g, GraphicsPath path)
{
2021-06-24 22:15:47 +08:00
int iin = Math.Min(inner, outer);
int iou = Math.Max(inner, outer);
if (iin == iou)
{
iou = iin + 1;
}
inner = iin;
outer = iou;
2021-04-09 17:39:28 +08:00
g.FillFan(ProcessBackColor, ClientRectangle.Center(), Inner, Outer, 0, 360);
g.FillFan(ProcessColor, ClientRectangle.Center(), Inner, Outer, -90, Value * 1.0f / Maximum * 360.0f);
}
2021-04-08 23:10:53 +08:00
2021-04-09 17:39:28 +08:00
public override void SetStyleColor(UIBaseStyle uiColor)
{
base.SetStyleColor(uiColor);
2021-04-11 12:04:09 +08:00
fillColor = uiColor.RectColor;
foreColor = uiColor.RectColor;
2021-04-09 17:39:28 +08:00
rectColor = uiColor.GridSelectedColor;
Invalidate();
}
2021-04-08 23:10:53 +08:00
2021-04-09 17:39:28 +08:00
public bool ShowProcess
2021-04-08 23:10:53 +08:00
{
2021-04-09 17:39:28 +08:00
get => ShowText;
set => ShowText = value;
2021-04-08 23:10:53 +08:00
}
}
}