【发布时间】:2020-08-26 10:44:27
【问题描述】:
有人可以帮我制作一个类,它可以创建一个带有特定圆角的按钮吗?
GraphicsPath GetRoundPath(RectangleF Rect, int radius, float width=0)
{
//Fix radius to rect size
radius = (int) Math.Max(( Math.Min(radius, Math.Min(Rect.Width, Rect.Height)) - width),1);
float r2 = radius / 2f;
float w2 = width / 2f;
GraphicsPath GraphPath = new GraphicsPath();
//Top-Left Arc
GraphPath.AddArc(Rect.X + w2, Rect.Y + w2, radius, radius, 180, 90);
//Top-Right Arc
GraphPath.AddArc(Rect.X + Rect.Width - radius - w2, Rect.Y + w2, radius, radius, 270, 90);
//Bottom-Right Arc
GraphPath.AddArc(Rect.X + Rect.Width - w2 - radius,
Rect.Y + Rect.Height - w2 - radius, radius, radius, 0, 90);
//Bottom-Left Arc
GraphPath.AddArc(Rect.X + w2, Rect.Y - w2 + Rect.Height - radius, radius, radius, 90, 90);
//Close line ( Left)
GraphPath.AddLine(Rect.X + w2, Rect.Y + Rect.Height - r2 - w2, Rect.X + w2,Rect.Y + r2 + w2);
return GraphPath;
}
【问题讨论】:
-
请出示您对此问题的尝试/代码。谢谢你:)
-
您好,我添加了代码,我需要一些解释,如何让一些角不圆?