* UIGroupBox: 解决Radius为0时的报错
This commit is contained in:
parent
c112b98c66
commit
8724325508
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -43,15 +43,7 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
protected override void OnPaintRect(Graphics g, GraphicsPath path)
|
protected override void OnPaintRect(Graphics g, GraphicsPath path)
|
||||||
{
|
{
|
||||||
//IsRadius为True时,显示左上圆角
|
path = new Rectangle(0, TitleTop, Width - 1, Height - _titleTop - 1).CreateRoundedRectanglePath(Radius, RadiusSides);
|
||||||
bool RadiusLeftTop = RadiusSides.GetValue(UICornerRadiusSides.LeftTop);
|
|
||||||
//IsRadius为True时,显示左下圆角
|
|
||||||
bool RadiusLeftBottom = RadiusSides.GetValue(UICornerRadiusSides.LeftBottom);
|
|
||||||
//IsRadius为True时,显示右上圆角
|
|
||||||
bool RadiusRightTop = RadiusSides.GetValue(UICornerRadiusSides.RightTop);
|
|
||||||
//IsRadius为True时,显示右下圆角
|
|
||||||
bool RadiusRightBottom = RadiusSides.GetValue(UICornerRadiusSides.RightBottom);
|
|
||||||
path = new Rectangle(0, TitleTop, Width - 1, Height - _titleTop - 1).CreateRoundedRectanglePath(Radius, RadiusLeftTop, RadiusRightTop, RadiusRightBottom, RadiusLeftBottom);
|
|
||||||
base.OnPaintRect(g, path);
|
base.OnPaintRect(g, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -697,7 +697,12 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
if (radiusSides == UICornerRadiusSides.None || radius == 0)
|
if (radiusSides == UICornerRadiusSides.None || radius == 0)
|
||||||
{
|
{
|
||||||
Point[] points = new Point[] { new Point(0, 0), new Point(rect.Width, 0), new Point(rect.Width, rect.Height), new Point(0, rect.Height), new Point(0, 0), };
|
Point[] points = new Point[] {
|
||||||
|
new Point(rect.Left, rect.Top),
|
||||||
|
new Point(rect.Right, rect.Top),
|
||||||
|
new Point(rect.Right, rect.Bottom),
|
||||||
|
new Point(rect.Left, rect.Bottom),
|
||||||
|
new Point(rect.Left, rect.Top) };
|
||||||
path = points.Path();
|
path = points.Path();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -889,27 +894,42 @@ namespace Sunny.UI
|
|||||||
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius, bool cornerLeftTop = true, bool cornerRightTop = true, bool cornerRightBottom = true, bool cornerLeftBottom = true)
|
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius, bool cornerLeftTop = true, bool cornerRightTop = true, bool cornerRightBottom = true, bool cornerLeftBottom = true)
|
||||||
{
|
{
|
||||||
GraphicsPath path = new GraphicsPath();
|
GraphicsPath path = new GraphicsPath();
|
||||||
if (cornerLeftTop)
|
|
||||||
path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
|
|
||||||
else
|
|
||||||
path.AddLine(new Point(rect.X, rect.Y + 1), new Point(rect.X, rect.Y));
|
|
||||||
|
|
||||||
if (cornerRightTop)
|
if ((!cornerLeftTop && !cornerRightTop && !cornerRightBottom && !cornerLeftBottom) || radius <= 0)
|
||||||
path.AddArc(rect.X + rect.Width - radius, rect.Y, radius, radius, 270, 90);
|
{
|
||||||
|
Point[] points = new Point[] {
|
||||||
|
new Point(rect.Left, rect.Top),
|
||||||
|
new Point(rect.Right, rect.Top),
|
||||||
|
new Point(rect.Right, rect.Bottom),
|
||||||
|
new Point(rect.Left, rect.Bottom),
|
||||||
|
new Point(rect.Left, rect.Top) };
|
||||||
|
path = points.Path();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
path.AddLine(new Point(rect.X + rect.Width - 1, rect.Y), new Point(rect.X + rect.Width, rect.Y));
|
{
|
||||||
|
if (cornerLeftTop)
|
||||||
|
path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
|
||||||
|
else
|
||||||
|
path.AddLine(new Point(rect.X, rect.Y + 1), new Point(rect.X, rect.Y));
|
||||||
|
|
||||||
if (cornerRightBottom)
|
if (cornerRightTop)
|
||||||
path.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90);
|
path.AddArc(rect.X + rect.Width - radius, rect.Y, radius, radius, 270, 90);
|
||||||
else
|
else
|
||||||
path.AddLine(new Point(rect.X + rect.Width, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y + rect.Height));
|
path.AddLine(new Point(rect.X + rect.Width - 1, rect.Y), new Point(rect.X + rect.Width, rect.Y));
|
||||||
|
|
||||||
if (cornerLeftBottom)
|
if (cornerRightBottom)
|
||||||
path.AddArc(rect.X, rect.Bottom - radius, radius, radius, 90, 90);
|
path.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90);
|
||||||
else
|
else
|
||||||
path.AddLine(new Point(rect.X + 1, rect.Y + rect.Height), new Point(rect.X, rect.Y + rect.Height));
|
path.AddLine(new Point(rect.X + rect.Width, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y + rect.Height));
|
||||||
|
|
||||||
|
if (cornerLeftBottom)
|
||||||
|
path.AddArc(rect.X, rect.Bottom - radius, radius, radius, 90, 90);
|
||||||
|
else
|
||||||
|
path.AddLine(new Point(rect.X + 1, rect.Y + rect.Height), new Point(rect.X, rect.Y + rect.Height));
|
||||||
|
|
||||||
|
path.CloseFigure();
|
||||||
|
}
|
||||||
|
|
||||||
path.CloseFigure();
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user