重构GDI一些方法

This commit is contained in:
Sunny 2023-10-30 11:19:41 +08:00
parent a04160cff2
commit 967c406885
26 changed files with 159 additions and 247 deletions

View File

@ -542,7 +542,8 @@ namespace Sunny.UI
points.Add(new PointF(lineSeries.Points[0].X, lineSeries.YOffsetPos));
points.AddRange(lineSeries.Points);
points.Add(new PointF(lineSeries.Points[series.Points.Count - 1].X, lineSeries.YOffsetPos));
g.FillPath(color, points.ToArray().Path());
using var path = points.ToArray().Path();
g.FillPath(color, path);
g.DrawLine(color, points[0], points[points.Count - 1]);
points.Clear();
}
@ -707,10 +708,9 @@ namespace Sunny.UI
PointF pt4 = new PointF(p.X, p.Y + series.SymbolSize);
PointF[] pts = { pt1, pt2, pt3, pt4, pt1 };
g.SetHighQuality();
GraphicsPath path = pts.Path();
using GraphicsPath path = pts.Path();
g.FillPath(br, path);
g.DrawPath(pn, path);
path.Dispose();
}
break;
case UILinePointSymbol.Triangle:
@ -720,10 +720,9 @@ namespace Sunny.UI
PointF pt3 = new PointF(p.X + series.SymbolSize * 0.866f, p.Y + series.SymbolSize * 0.5f);
PointF[] pts = { pt1, pt2, pt3, pt1 };
g.SetHighQuality();
GraphicsPath path = pts.Path();
using GraphicsPath path = pts.Path();
g.FillPath(br, path);
g.DrawPath(pn, path);
path.Dispose();
}
break;
case UILinePointSymbol.Circle:

View File

@ -51,13 +51,9 @@ namespace Sunny.UI
/// <returns>是否在区域内</returns>
public static bool InRegion(this Point point, Point[] points)
{
using (GraphicsPath path = points.Path())
{
using (Region region = path.Region())
{
return region.IsVisible(point);
}
}
using GraphicsPath path = points.Path();
using Region region = path.Region();
return region.IsVisible(point);
}
/// <summary>
@ -68,13 +64,9 @@ namespace Sunny.UI
/// <returns>是否在区域内</returns>
public static bool InRegion(this PointF point, PointF[] points)
{
using (GraphicsPath path = points.Path())
{
using (Region region = path.Region())
{
return region.IsVisible(point);
}
}
using GraphicsPath path = points.Path();
using Region region = path.Region();
return region.IsVisible(point);
}
/// <summary>

View File

@ -165,30 +165,27 @@ namespace Sunny.UI
{
//截图画板
Bitmap result = new Bitmap(size, size);
Graphics g = System.Drawing.Graphics.FromImage(result);
//创建截图路径类似Ps里的路径
GraphicsPath path = new GraphicsPath();
using Graphics g = System.Drawing.Graphics.FromImage(result);
g.SetHighQuality();
if (shape == UIShape.Circle)
{
//创建截图路径类似Ps里的路径
using GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, size, size);//圆形
//设置画板的截图路径
g.SetClip(path);
}
if (shape == UIShape.Square)
{
path.Dispose();
path = new Rectangle(0, 0, size, size).CreateRoundedRectanglePath(5);//圆形
using GraphicsPath path = new Rectangle(0, 0, size, size).CreateRoundedRectanglePath(5);//圆形
//设置画板的截图路径
g.SetClip(path);
}
g.SetHighQuality();
//设置画板的截图路径
g.SetClip(path);
//对图片进行截图
g.DrawImage(image, 0, 0);
//保存截好的图
g.Dispose();
path.Dispose();
return result;
}

View File

@ -1693,10 +1693,8 @@ namespace Sunny.UI
/// <param name="radius">圆角半径</param>
public static void DrawRectangle(Graphics g, Rectangle rectangle, Brush brush = null, Border border = null, int radius = 0)
{
using (var path = GetRoundedRectangle(rectangle, radius))
{
DrawPath(g, path, brush, border);
}
using var path = GetRoundedRectangle(rectangle, radius);
DrawPath(g, path, brush, border);
}
/// <summary>

View File

@ -211,7 +211,7 @@ namespace Sunny.UI
cornerRadius = (float)Math.Min(cornerRadius, Math.Floor(r.Width) - 2);
cornerRadius = (float)Math.Min(cornerRadius, Math.Floor(r.Height) - 2);
GraphicsPath path = new GraphicsPath();
using GraphicsPath path = new GraphicsPath();
path.AddArc(r.X, r.Y, cornerRadius, cornerRadius, 180, 90);
path.AddArc(r.Right - cornerRadius, r.Y, cornerRadius, cornerRadius, 270, 90);
path.AddArc(r.Right - cornerRadius, r.Bottom - cornerRadius, cornerRadius, cornerRadius, 0, 90);
@ -232,9 +232,8 @@ namespace Sunny.UI
if (lr1.Height > 0 && lr1.Width > 0)
{
LinearGradientBrush lb1 = new LinearGradientBrush(lr1, c1, c2, angle, false);
using LinearGradientBrush lb1 = new LinearGradientBrush(lr1, c1, c2, angle, false);
dc.FillRectangle(lb1, lr1);
lb1.Dispose();
}
}
@ -265,38 +264,31 @@ namespace Sunny.UI
if (lr1.Height > 0 && lr1.Width > 0)
{
LinearGradientBrush lb2 = new LinearGradientBrush(lr2, c1, c2, angle, false);
LinearGradientBrush lb1 = new LinearGradientBrush(lr1, c2, c3, angle, false);
using LinearGradientBrush lb2 = new LinearGradientBrush(lr2, c1, c2, angle, false);
using LinearGradientBrush lb1 = new LinearGradientBrush(lr1, c2, c3, angle, false);
dc.FillRectangle(lb1, lr1);
dc.FillRectangle(lb2, lr2);
lb1.Dispose();
lb2.Dispose();
}
// with some sizes the first pixel in the gradient rectangle shows the opposite color
// this is a workaround for that problem
if (orientation == Orientation.Vertical)
{
Pen pc2 = new Pen(c2, 1);
Pen pc3 = new Pen(c3, 1);
using Pen pc2 = new Pen(c2, 1);
using Pen pc3 = new Pen(c3, 1);
dc.DrawLine(pc3, lr1.Left, lr1.Top, lr1.Right - 1, lr1.Top);
dc.DrawLine(pc2, lr2.Left, lr2.Top, lr2.Right - 1, lr2.Top);
pc2.Dispose();
pc3.Dispose();
}
if (orientation == Orientation.Horizontal)
{
Pen pc1 = new Pen(c1, 1);
Pen pc2 = new Pen(c2, 1);
Pen pc3 = new Pen(c3, 1);
using Pen pc1 = new Pen(c1, 1);
using Pen pc2 = new Pen(c2, 1);
using Pen pc3 = new Pen(c3, 1);
dc.DrawLine(pc1, lr2.Left, lr2.Top, lr2.Left, lr2.Bottom - 1);
dc.DrawLine(pc2, lr2.Right, lr2.Top, lr2.Right, lr2.Bottom - 1);
dc.DrawLine(pc3, lr1.Right, lr1.Top, lr1.Right, lr1.Bottom - 1);
pc1.Dispose();
pc2.Dispose();
pc3.Dispose();
}
}
}

View File

@ -368,17 +368,15 @@ namespace Sunny.UI
scaleImage.Dispose();
e.Graphics.SetHighQuality();
using (Pen pn = new Pen(BackColor, 4))
using Pen pn = new Pen(BackColor, 4);
if (Shape == UIShape.Circle)
{
if (Shape == UIShape.Circle)
{
e.Graphics.DrawEllipse(pn, (Width - avatarSize) / 2 + 1 + ImageOffset.X, (Height - avatarSize) / 2 + 1 + ImageOffset.Y, size, size);
}
e.Graphics.DrawEllipse(pn, (Width - avatarSize) / 2 + 1 + ImageOffset.X, (Height - avatarSize) / 2 + 1 + ImageOffset.Y, size, size);
}
if (Shape == UIShape.Square)
{
e.Graphics.DrawRoundRectangle(pn, (Width - avatarSize) / 2 + 1 + ImageOffset.X, (Height - avatarSize) / 2 + 1 + ImageOffset.Y, size, size, 5);
}
if (Shape == UIShape.Square)
{
e.Graphics.DrawRoundRectangle(pn, (Width - avatarSize) / 2 + 1 + ImageOffset.X, (Height - avatarSize) / 2 + 1 + ImageOffset.Y, size, size, 5);
}
e.Graphics.SetDefaultQuality();

View File

@ -253,7 +253,7 @@ namespace Sunny.UI
br.GammaCorrection = true;
g.FillPath(br, path);
br.Dispose();
br?.Dispose();
}
}
else
@ -325,14 +325,10 @@ namespace Sunny.UI
if (Focused && ShowFocusLine)
{
Rectangle rect = new Rectangle(2, 2, Width - 5, Height - 5);
var path = rect.CreateRoundedRectanglePath(Radius);
using (Pen pn = new Pen(ForeColor))
{
pn.DashStyle = DashStyle.Dot;
e.Graphics.DrawPath(pn, path);
}
path.Dispose();
using var path = rect.CreateRoundedRectanglePath(Radius);
using Pen pn = new Pen(ForeColor);
pn.DashStyle = DashStyle.Dot;
e.Graphics.DrawPath(pn, path);
}
}

View File

@ -211,27 +211,22 @@ namespace Sunny.UI
if (Checked)
{
g.FillRoundRectangle(color, new Rectangle((int)left, (int)top, ImageSize, ImageSize), 1);
color = BackColor.IsValid() ? BackColor : Color.White;
Point pt2 = new Point((int)(left + ImageSize * 2 / 5.0f), (int)(top + ImageSize * 3 / 4.0f) - (ImageSize.Div(10)));
Point pt1 = new Point((int)left + 2 + ImageSize.Div(10), pt2.Y - (pt2.X - 2 - ImageSize.Div(10) - (int)left));
Point pt3 = new Point((int)left + ImageSize - 2 - ImageSize.Div(10), pt2.Y - (ImageSize - pt2.X - 2 - ImageSize.Div(10)) - (int)left);
PointF[] CheckMarkLine = { pt1, pt2, pt3 };
using (Pen pn = new Pen(color, 2))
{
g.SetHighQuality();
g.DrawLines(pn, CheckMarkLine);
g.SetDefaultQuality();
}
using Pen pn = new Pen(color, 2);
g.SetHighQuality();
g.DrawLines(pn, CheckMarkLine);
g.SetDefaultQuality();
}
else
{
using (Pen pn = new Pen(color, 1))
{
g.DrawRoundRectangle(pn, new Rectangle((int)left + 1, (int)top + 1, ImageSize - 2, ImageSize - 2), 1);
g.DrawRectangle(pn, new Rectangle((int)left + 2, (int)top + 2, ImageSize - 4, ImageSize - 4));
}
using Pen pn = new Pen(color, 1);
g.DrawRoundRectangle(pn, new Rectangle((int)left + 1, (int)top + 1, ImageSize - 2, ImageSize - 2), 1);
g.DrawRectangle(pn, new Rectangle((int)left + 2, (int)top + 2, ImageSize - 4, ImageSize - 4));
}
}

View File

@ -168,8 +168,8 @@ namespace Sunny.UI
{
base.OnPaintFore(g, path);
if (Text.IsValid()) Text = "";
var pathColor = g.CreateRoundedRectanglePath(new Rectangle(3, 3, Width - 32, Height - 7), 3, UICornerRadiusSides.All);
g.FillPath(Value, pathColor);
using var colorPath = g.CreateRoundedRectanglePath(new Rectangle(3, 3, Width - 32, Height - 7), 3, UICornerRadiusSides.All);
g.FillPath(Value, colorPath);
}
/// <summary>

View File

@ -419,7 +419,7 @@ namespace Sunny.UI
if (IsDisposed) return;
Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);
GraphicsPath path = rect.CreateRoundedRectanglePath(radius, RadiusSides, RectSize);
using GraphicsPath path = rect.CreateRoundedRectanglePath(radius, RadiusSides, RectSize);
//填充背景色
if (ShowFill && fillColor.IsValid())
@ -439,7 +439,6 @@ namespace Sunny.UI
OnPaintFore(e.Graphics, path);
}
path.Dispose();
base.OnPaint(e);
}

View File

@ -73,13 +73,13 @@ namespace Sunny.UI
var rect = new Rectangle(0, TitleTop, Width - 1, Height - _titleTop - 1);
if (Text.IsValid())
{
path = rect.CreateRoundedRectanglePathWithoutTop(Radius, RadiusSides, RectSize);
g.DrawPath(GetRectColor(), path, true, RectSize);
using var path1 = rect.CreateRoundedRectanglePathWithoutTop(Radius, RadiusSides, RectSize);
g.DrawPath(GetRectColor(), path1, true, RectSize);
}
else
{
path = rect.CreateRoundedRectanglePath(Radius, RadiusSides, RectSize);
g.DrawPath(GetRectColor(), path, true, RectSize);
using var path1 = rect.CreateRoundedRectanglePath(Radius, RadiusSides, RectSize);
g.DrawPath(GetRectColor(), path1, true, RectSize);
}
}

View File

@ -243,25 +243,22 @@ namespace Sunny.UI
g.FillRectangle(fillColor, rect);
g.SetHighQuality();
using (var pen = new Pen(clr_arrow, 2))
using var pen = new Pen(clr_arrow, 2);
Point pt1, pt2, pt3;
if (!isUp)
{
Point pt1, pt2, pt3;
if (!isUp)
{
pt1 = new Point(Width - 16 / 2 - 4, Height / 2 - 4);
pt2 = new Point(Width - 16 / 2, Height / 2);
pt3 = new Point(Width - 16 / 2 - 4, Height / 2 + 4);
}
else
{
pt1 = new Point(16 / 2 + 4 - 1, Height / 2 - 4);
pt2 = new Point(16 / 2 - 1, Height / 2);
pt3 = new Point(16 / 2 + 4 - 1, Height / 2 + 4);
}
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
pt1 = new Point(Width - 16 / 2 - 4, Height / 2 - 4);
pt2 = new Point(Width - 16 / 2, Height / 2);
pt3 = new Point(Width - 16 / 2 - 4, Height / 2 + 4);
}
else
{
pt1 = new Point(16 / 2 + 4 - 1, Height / 2 - 4);
pt2 = new Point(16 / 2 - 1, Height / 2);
pt3 = new Point(16 / 2 + 4 - 1, Height / 2 + 4);
}
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
g.SetDefaultQuality();
}

View File

@ -222,25 +222,22 @@ namespace Sunny.UI
g.FillRectangle(fillColor, isUp ? GetUpRect() : GetDownRect());
g.SetHighQuality();
using (var pen = new Pen(clr_arrow, 2))
using var pen = new Pen(clr_arrow, 2);
Point pt1, pt2, pt3;
if (!isUp)
{
Point pt1, pt2, pt3;
if (!isUp)
{
pt1 = new Point(Width - 16 / 2 - 4, Height / 2 - 4);
pt2 = new Point(Width - 16 / 2, Height / 2);
pt3 = new Point(Width - 16 / 2 - 4, Height / 2 + 4);
}
else
{
pt1 = new Point(16 / 2 + 4 - 1, Height / 2 - 4);
pt2 = new Point(16 / 2 - 1, Height / 2);
pt3 = new Point(16 / 2 + 4 - 1, Height / 2 + 4);
}
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
pt1 = new Point(Width - 16 / 2 - 4, Height / 2 - 4);
pt2 = new Point(Width - 16 / 2, Height / 2);
pt3 = new Point(Width - 16 / 2 - 4, Height / 2 + 4);
}
else
{
pt1 = new Point(16 / 2 + 4 - 1, Height / 2 - 4);
pt2 = new Point(16 / 2 - 1, Height / 2);
pt3 = new Point(16 / 2 + 4 - 1, Height / 2 + 4);
}
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
g.SetDefaultQuality();
}

View File

@ -891,7 +891,6 @@ namespace Sunny.UI
// Draw pointer arrow that shows knob position
Rectangle rPointer = new Rectangle(Arrow.X - w / 2, Arrow.Y - w / 2, w, h);
//Utility.DrawInsetCircle(ref Gr, rPointer, new Pen(_PointerColor));
using Pen pen = new Pen(GetLightColor(_PointerColor, 55));
DrawInsetCircle(ref Gr, rPointer, pen);
Gr.FillEllipse(brushKnobPointer, rPointer);
@ -929,11 +928,8 @@ namespace Sunny.UI
float radius = (float)(rc.Width / 2);
float rulerValue = (float)_minimum;
Font font;
using Pen penL = new Pen(_scaleColor, (2 * drawRatio));
using Pen penS = new Pen(_scaleColor, (1 * drawRatio));
using SolidBrush br = new SolidBrush(_scaleColor);
PointF ptStart = new PointF(0, 0);
@ -963,7 +959,7 @@ namespace Sunny.UI
fSize = _scaleFont.Size;
}
font = new Font(_scaleFont.FontFamily, fSize);
using var font = new Font(_scaleFont.FontFamily, fSize);
strsize = TextRenderer.MeasureText(str, font);
int strw = (int)strsize.Width;
@ -1051,8 +1047,6 @@ namespace Sunny.UI
#endregion
}
font.Dispose();
}
return true;

View File

@ -176,27 +176,25 @@ namespace Sunny.UI
g.FillEllipse(darkColor, rectangle);
// Draw the glow gradient
var path = new GraphicsPath();
using var path = new GraphicsPath();
path.AddEllipse(rectangle);
var pathBrush = new PathGradientBrush(path);
using var pathBrush = new PathGradientBrush(path);
pathBrush.CenterColor = lightColor;
pathBrush.SurroundColors = new[] { Color.FromArgb(0, lightColor) };
g.SetHighQuality();
g.FillEllipse(pathBrush, rectangle);
pathBrush.Dispose();
// Draw the white reflection gradient
var offset = Convert.ToInt32(diameter * .15F);
var diameter1 = Convert.ToInt32(rectangle.Width * .8F);
var whiteRect = new Rectangle(rectangle.X - offset, rectangle.Y - offset, diameter1, diameter1);
var path1 = new GraphicsPath();
using var path1 = new GraphicsPath();
path1.AddEllipse(whiteRect);
var pathBrush1 = new PathGradientBrush(path);
using var pathBrush1 = new PathGradientBrush(path);
pathBrush1.CenterColor = _reflectionColor;
pathBrush1.SurroundColors = _surroundColor;
g.SetHighQuality();
g.FillEllipse(pathBrush1, whiteRect);
pathBrush1.Dispose();
// Draw the border
g.SetClip(ClientRectangle);
@ -204,10 +202,8 @@ namespace Sunny.UI
if (On)
{
using (Pen pn = new Pen(Color.FromArgb(85, Color.Black), 1F))
{
g.DrawEllipse(pn, rectangle);
}
using Pen pn = new Pen(Color.FromArgb(85, Color.Black), 1F);
g.DrawEllipse(pn, rectangle);
}
g.SetDefaultQuality();

View File

@ -180,7 +180,7 @@ namespace Sunny.UI
if (Shape == UIShape.Circle)
{
if (Radius != ShowSize) Radius = ShowSize;
GraphicsPath CirclePath = new GraphicsPath();
using GraphicsPath CirclePath = new GraphicsPath();
CirclePath.AddEllipse(2, 2, ShowSize - 4, ShowSize - 4);
g.Smooth();
@ -188,26 +188,21 @@ namespace Sunny.UI
{
Color[] surroundColor = new Color[] { color };
using GraphicsPath path1 = ClientRectangle.CreateTrueRoundedRectanglePath(Height);
PathGradientBrush gradientBrush = new PathGradientBrush(path1);
using PathGradientBrush gradientBrush = new PathGradientBrush(path1);
gradientBrush.CenterPoint = new PointF(ShowSize / 2.0f, ShowSize / 2.0f);
gradientBrush.CenterColor = cColor;
gradientBrush.SurroundColors = surroundColor;
g.FillPath(gradientBrush, CirclePath);
gradientBrush.Dispose();
}
else
{
g.FillPath(color, CirclePath);
}
CirclePath.Dispose();
if (ShowLightLine)
{
int size = (ShowSize - 4) / 5;
g.DrawArc(cColor, size, size,
ShowSize - size * 2, ShowSize - size * 2,
45, -155);
g.DrawArc(cColor, size, size, ShowSize - size * 2, ShowSize - size * 2, 45, -155);
}
}
@ -218,7 +213,7 @@ namespace Sunny.UI
if (ShowCenterColor)
{
GraphicsPath CirclePath = new GraphicsPath();
using GraphicsPath CirclePath = new GraphicsPath();
Point[] p = {
new Point(3,3),new Point(ShowSize-3,3),
new Point(ShowSize-3,ShowSize-3),new Point(3,ShowSize-3)
@ -228,13 +223,11 @@ namespace Sunny.UI
g.Smooth();
Color[] surroundColor = new Color[] { color };
PathGradientBrush gradientBrush = new PathGradientBrush(path);
using PathGradientBrush gradientBrush = new PathGradientBrush(path);
gradientBrush.CenterPoint = new PointF(ShowSize / 2.0f, ShowSize / 2.0f);
gradientBrush.CenterColor = cColor;
gradientBrush.SurroundColors = surroundColor;
g.FillPath(gradientBrush, CirclePath);
gradientBrush.Dispose();
CirclePath.Dispose();
}
}
}

View File

@ -487,7 +487,7 @@ namespace Sunny.UI
}
else
{
var path = rect.CreateRoundedRectanglePath(Radius, UICornerRadiusSides.LeftTop | UICornerRadiusSides.RightTop);
using var path = rect.CreateRoundedRectanglePath(Radius, UICornerRadiusSides.LeftTop | UICornerRadiusSides.RightTop);
e.Graphics.FillPath(MenuHoverColor, path);
}
@ -504,7 +504,7 @@ namespace Sunny.UI
}
else
{
var path = new Rectangle(rect.X, Height - NodeSize.Height, rect.Width, NodeSize.Height).CreateRoundedRectanglePath(Radius, UICornerRadiusSides.LeftTop | UICornerRadiusSides.RightTop);
using var path = new Rectangle(rect.X, Height - NodeSize.Height, rect.Width, NodeSize.Height).CreateRoundedRectanglePath(Radius, UICornerRadiusSides.LeftTop | UICornerRadiusSides.RightTop);
e.Graphics.FillPath(MenuSelectedColor, path);
}
}

View File

@ -669,10 +669,9 @@ namespace Sunny.UI
{
if (SelectedColorGradient)
{
LinearGradientBrush br = new LinearGradientBrush(new Point(0, 0), new Point(0, e.Node.Bounds.Height), SelectedColor, SelectedColor2);
using LinearGradientBrush br = new LinearGradientBrush(new Point(0, 0), new Point(0, e.Node.Bounds.Height), SelectedColor, SelectedColor2);
br.GammaCorrection = true;
e.Graphics.FillRectangle(br, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height)));
br.Dispose();
}
else
{

View File

@ -338,8 +338,7 @@ namespace Sunny.UI
if (Height < Width * 2 + 4) return;
w = Width.Div(2) + Width.Mod(2);
if (RadiusSides.HasFlag(UICornerRadiusSides.LeftTop) &&
!RadiusSides.HasFlag(UICornerRadiusSides.RightTop))
if (RadiusSides.HasFlag(UICornerRadiusSides.LeftTop) && !RadiusSides.HasFlag(UICornerRadiusSides.RightTop))
{
for (int i = 1; i < w; i++)
{
@ -358,8 +357,7 @@ namespace Sunny.UI
}
}
if (!RadiusSides.HasFlag(UICornerRadiusSides.LeftTop) &&
RadiusSides.HasFlag(UICornerRadiusSides.RightTop))
if (!RadiusSides.HasFlag(UICornerRadiusSides.LeftTop) && RadiusSides.HasFlag(UICornerRadiusSides.RightTop))
{
for (int i = 1; i < w; i++)
{
@ -382,8 +380,7 @@ namespace Sunny.UI
}
}
if (RadiusSides.HasFlag(UICornerRadiusSides.LeftBottom) &&
!RadiusSides.HasFlag(UICornerRadiusSides.RightBottom))
if (RadiusSides.HasFlag(UICornerRadiusSides.LeftBottom) && !RadiusSides.HasFlag(UICornerRadiusSides.RightBottom))
{
for (int i = 1; i < w; i++)
{
@ -402,8 +399,7 @@ namespace Sunny.UI
}
}
if (!RadiusSides.HasFlag(UICornerRadiusSides.LeftBottom) &&
RadiusSides.HasFlag(UICornerRadiusSides.RightBottom))
if (!RadiusSides.HasFlag(UICornerRadiusSides.LeftBottom) && RadiusSides.HasFlag(UICornerRadiusSides.RightBottom))
{
for (int i = 1; i < w; i++)
{
@ -536,8 +532,8 @@ namespace Sunny.UI
private Bitmap CreatePipeBack(UIPipe pipe)
{
Bitmap result = new Bitmap(pipe.Width, pipe.Height);
Graphics g = result.Graphics();
var path = result.Bounds().CreateRoundedRectanglePath(5, UICornerRadiusSides.None);
using Graphics g = result.Graphics();
using var path = result.Bounds().CreateRoundedRectanglePath(5, UICornerRadiusSides.None);
int h = pipe.Height.Div(2) + pipe.Height.Mod(2);
using (Bitmap bmp = new Bitmap(pipe.Width, pipe.Height))
@ -567,7 +563,6 @@ namespace Sunny.UI
g.DrawImage(bmp, new Rectangle(0, h, pipe.Width, pipe.Height - h), new Rectangle(0, h, pipe.Width, pipe.Height - h), GraphicsUnit.Pixel);
}
g.Dispose();
return result;
}

View File

@ -212,12 +212,10 @@ namespace Sunny.UI
}
else
{
using (Pen pn = new Pen(color, 2))
{
g.SetHighQuality();
g.DrawEllipse(pn, left + 1, top + 1, ImageSize - 2, ImageSize - 2);
g.SetDefaultQuality();
}
using Pen pn = new Pen(color, 2);
g.SetHighQuality();
g.DrawEllipse(pn, left + 1, top + 1, ImageSize - 2, ImageSize - 2);
g.SetDefaultQuality();
}
}

View File

@ -263,25 +263,22 @@ namespace Sunny.UI
g.FillRectangle(fillColor, rect);
g.SetHighQuality();
using (var pen = new Pen(clr_arrow, 2))
using var pen = new Pen(clr_arrow, 2);
Point pt1, pt2, pt3;
if (!isUp)
{
Point pt1, pt2, pt3;
if (!isUp)
{
pt1 = new Point(Width / 2 - 4, Height - 16 / 2 - 4);
pt2 = new Point(Width / 2, Height - 16 / 2);
pt3 = new Point(Width / 2 + 4, Height - 16 / 2 - 4);
}
else
{
pt1 = new Point(Width / 2 - 4, 16 / 2 + 4 - 1);
pt2 = new Point(Width / 2, 16 / 2 - 1);
pt3 = new Point(Width / 2 + 4, 16 / 2 + 4 - 1);
}
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
pt1 = new Point(Width / 2 - 4, Height - 16 / 2 - 4);
pt2 = new Point(Width / 2, Height - 16 / 2);
pt3 = new Point(Width / 2 + 4, Height - 16 / 2 - 4);
}
else
{
pt1 = new Point(Width / 2 - 4, 16 / 2 + 4 - 1);
pt2 = new Point(Width / 2, 16 / 2 - 1);
pt3 = new Point(Width / 2 + 4, 16 / 2 + 4 - 1);
}
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
g.SetDefaultQuality();
}

View File

@ -140,10 +140,10 @@ namespace Sunny.UI
bool RadiusLeftTop = RadiusSides.GetValue(UICornerRadiusSides.LeftTop);
//IsRadius为True时显示右上圆角
bool RadiusRightTop = RadiusSides.GetValue(UICornerRadiusSides.RightTop);
path = GetTitleFillPath(Radius, TitleHeight, RadiusLeftTop, RadiusRightTop);
using var path1 = GetTitleFillPath(Radius, TitleHeight, RadiusLeftTop, RadiusRightTop);
Color color = Enabled ? TitleColor : UIDisableColor.Fill;
g.FillPath(color, path);
g.FillPath(color, path1);
if (Height > TitleHeight)
g.DrawLine(RectColor, 0, TitleHeight, Width, TitleHeight);

View File

@ -171,19 +171,15 @@ namespace Sunny.UI
g.FillRoundRectangle(fillColor.IsValid() ? fillColor : Color.White,
new Rectangle(len, (Height - BarSize) / 2, 10, BarSize), 5);
using (Pen pen = new Pen(rectColor, 2))
{
g.SetHighQuality();
g.DrawRoundRectangle(pen,
new Rectangle(len + 1, (Height - BarSize) / 2 + 1, 8, BarSize - 2), 5);
g.SetDefaultQuality();
}
using Pen pen = new Pen(rectColor, 2);
g.SetHighQuality();
g.DrawRoundRectangle(pen, new Rectangle(len + 1, (Height - BarSize) / 2 + 1, 8, BarSize - 2), 5);
g.SetDefaultQuality();
}
if (Direction == BarDirection.Vertical)
{
g.FillRoundRectangle(rectDisableColor,
new Rectangle(Width / 2 - 3, 5, 6, Height - 1 - 10), 6);
g.FillRoundRectangle(rectDisableColor, new Rectangle(Width / 2 - 3, 5, 6, Height - 1 - 10), 6);
int len = (int)((Value - Minimum) * 1.0 * (Height - 1 - 10) / (Maximum - Minimum));
if (len > 0)
@ -191,16 +187,12 @@ namespace Sunny.UI
g.FillRoundRectangle(foreColor, new Rectangle(Width / 2 - 3, Height - len - 5, 6, len), 6);
}
g.FillRoundRectangle(fillColor.IsValid() ? fillColor : Color.White,
new Rectangle((Width - BarSize) / 2, Height - len - 10 - 1, BarSize, 10), 5);
g.FillRoundRectangle(fillColor.IsValid() ? fillColor : Color.White, new Rectangle((Width - BarSize) / 2, Height - len - 10 - 1, BarSize, 10), 5);
using (Pen pen = new Pen(rectColor, 2))
{
g.SetHighQuality();
g.DrawRoundRectangle(pen,
new Rectangle((Width - BarSize) / 2 + 1, Height - len - 10, BarSize - 2, 8), 5);
g.SetDefaultQuality();
}
using Pen pen = new Pen(rectColor, 2);
g.SetHighQuality();
g.DrawRoundRectangle(pen, new Rectangle((Width - BarSize) / 2 + 1, Height - len - 10, BarSize - 2, 8), 5);
g.SetDefaultQuality();
}
}

View File

@ -1121,20 +1121,17 @@ namespace Sunny.UI
}
else
{
using (var pn = new Pen(checkboxColor, 2))
{
var pt1 = new Point(checkBoxLeft + 2 + 2, e.Bounds.Y + (ItemHeight - 12) / 2 - 1 + 5);
var pt2 = new Point(pt1.X + 3, pt1.Y + 3);
var pt3 = new Point(pt2.X + 5, pt2.Y - 5);
using var pn = new Pen(checkboxColor, 2);
var pt1 = new Point(checkBoxLeft + 2 + 2, e.Bounds.Y + (ItemHeight - 12) / 2 - 1 + 5);
var pt2 = new Point(pt1.X + 3, pt1.Y + 3);
var pt3 = new Point(pt2.X + 5, pt2.Y - 5);
PointF[] CheckMarkLine = { pt1, pt2, pt3 };
PointF[] CheckMarkLine = { pt1, pt2, pt3 };
e.Graphics.SetHighQuality();
e.Graphics.DrawLines(pn, CheckMarkLine);
e.Graphics.SetDefaultQuality();
e.Graphics.DrawRectangle(checkboxColor,
new Rectangle(checkBoxLeft + 2, e.Bounds.Y + (ItemHeight - 12) / 2 - 1, 12, 12));
}
e.Graphics.SetHighQuality();
e.Graphics.DrawLines(pn, CheckMarkLine);
e.Graphics.SetDefaultQuality();
e.Graphics.DrawRectangle(checkboxColor, new Rectangle(checkBoxLeft + 2, e.Bounds.Y + (ItemHeight - 12) / 2 - 1, 12, 12));
}
if (DicNodeStatus[e.Node.GetHashCode()])
@ -1161,7 +1158,7 @@ namespace Sunny.UI
try
{
//绘制虚线
var pn = new Pen(LineColor);
using var pn = new Pen(LineColor);
pn.DashStyle = DashStyle.Dot;
e.Graphics.DrawLine(pn, lineX, lineY, lineX + 10, lineY);
@ -1199,8 +1196,6 @@ namespace Sunny.UI
e.Graphics.DrawLine(pn, lineX, lineY, lineX, e.Node.Bounds.Bottom);
}
}
pn.Dispose();
}
catch (Exception exception)
{

View File

@ -394,7 +394,7 @@ namespace Sunny.UI
if (IsDisposed) return;
Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);
GraphicsPath path = rect.CreateRoundedRectanglePath(radius, RadiusSides, RectSize);
using GraphicsPath path = rect.CreateRoundedRectanglePath(radius, RadiusSides, RectSize);
//填充背景色
if (BackgroundImage == null && ShowFill && fillColor.IsValid())
@ -410,12 +410,8 @@ namespace Sunny.UI
//填充文字
rect = new Rectangle(1, 1, Width - 3, Height - 3);
using (var path1 = rect.GraphicsPath())
{
OnPaintFore(e.Graphics, path1);
}
path.Dispose();
using var path1 = rect.GraphicsPath();
OnPaintFore(e.Graphics, path1);
base.OnPaint(e);
}

View File

@ -223,25 +223,22 @@ namespace Sunny.UI
g.FillRectangle(fillColor, isUp ? GetUpRect() : GetDownRect());
g.SetHighQuality();
using (var pen = new Pen(clr_arrow, 2))
using var pen = new Pen(clr_arrow, 2);
Point pt1, pt2, pt3;
if (!isUp)
{
Point pt1, pt2, pt3;
if (!isUp)
{
pt1 = new Point(Width / 2 - 4, Height - 16 / 2 - 4);
pt2 = new Point(Width / 2, Height - 16 / 2);
pt3 = new Point(Width / 2 + 4, Height - 16 / 2 - 4);
}
else
{
pt1 = new Point(Width / 2 - 4, 16 / 2 + 4 - 1);
pt2 = new Point(Width / 2, 16 / 2 - 1);
pt3 = new Point(Width / 2 + 4, 16 / 2 + 4 - 1);
}
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
pt1 = new Point(Width / 2 - 4, Height - 16 / 2 - 4);
pt2 = new Point(Width / 2, Height - 16 / 2);
pt3 = new Point(Width / 2 + 4, Height - 16 / 2 - 4);
}
else
{
pt1 = new Point(Width / 2 - 4, 16 / 2 + 4 - 1);
pt2 = new Point(Width / 2, 16 / 2 - 1);
pt3 = new Point(Width / 2 + 4, 16 / 2 + 4 - 1);
}
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
g.SetDefaultQuality();
}