RaUI/Source/ryControls/Gdu.WinFormUI/Painter/SimpleObjectPainter.cs
鑫Intel 5d65c76f05 ### 2021-12-14更新
------
#### MyDbV4    V3.0.2112.1401
- *.[修复]修复MSSQL的ExecuteNonQuery函数可能因为报错导致软件崩溃的BUG。
2021-12-14 09:37:57 +08:00

86 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using MGdu.WinFormUI.MyGraphics;
namespace MGdu.WinFormUI
{
/// <summary>
/// SimpleObject指的是只有一种状态不像普通按钮一样有三种状态并且其上的元素
/// 布局比较简单的Object
/// </summary>
public class SimpleObjectPainter
{
/// <summary>
///
/// </summary>
/// <param name="g"></param>
/// <param name="rect"></param>
/// <param name="coveredColor"></param>
/// <param name="borderColor"></param>
/// <param name="backColor"></param>
/// <param name="drawInnerBorder"></param>
/// <param name="startAngle"></param>
/// <param name="percentage"></param>
/// <param name="drawText"></param>
/// <param name="textFont"></param>
public static void RenderCircleProgressBar(Graphics g, Rectangle rect, Color coveredColor, Color borderColor,
Color backColor, bool drawInnerBorder, int startAngle, float percentage, bool drawText, Font textFont)
{
using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.AntiAlias))
{
Rectangle backup = rect;
rect.Width--;
rect.Height--;
if (percentage < 0)
percentage = 0;
if (percentage > 360)
percentage = 360;
SolidBrush brushBack = new SolidBrush(backColor);
Pen penBorder = new Pen(borderColor);
// fill background
g.FillEllipse(brushBack, rect);
// outter most circle
g.DrawEllipse(penBorder, rect);
// pie covered region
rect.Inflate(-1, -1);
if (drawInnerBorder)
rect.Inflate(-1, -1);
using (SolidBrush sb = new SolidBrush(coveredColor))
{
g.FillPie(sb, rect, startAngle, 360 * percentage /100);
}
// inner circle background
rect = backup;
rect.Inflate(-rect.Width / 4, -rect.Width / 4);
g.FillEllipse(brushBack, rect);
// inner circle line
rect.Inflate(-1, -1);
if (drawInnerBorder)
rect.Inflate(-1, -1);
g.DrawEllipse(penBorder, rect);
// text
if (drawText)
{
string text = percentage.ToString() + "%";
TextRenderer.DrawText(g, text, textFont, backup, Color.Black,
TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
}
brushBack.Dispose();
penBorder.Dispose();
}
}
}
}