获取圆角矩形的线
private void DrawRoundRect(GraphicsPath gp, float X, float Y, float width, float height, float radius)
{
gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);
gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);
gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));
gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);
gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);
gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);
gp.CloseFigure();
}
复制代码
绘制
//创建画板
Graphics g = CreateGraphics();
//清除
g.Clear(BackColor);
//圆角矩形的线
GraphicsPath gp = new GraphicsPath();
DrawRoundRect(gp, 900, 200, 100, 100, 10);
//绘制线
g.DrawPath(new Pen(Color.Gray, 2), gp);
//释放
gp.Dispose();
g.Dispose();
复制代码
效果

绘制圆角矩形填充内部
DrawPath只是绘制线,可以使用FillPath填充内部
g.FillPath(Brushes.SkyBlue, gp);
复制代码
效果
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END