C# 绘制圆角矩形

时间:2023-03-09 19:09:13
C# 绘制圆角矩形
Graphics g = e.Graphics;

            // 圆角半径
int cRadius = ; // 要实现 圆角化的 矩形
Rectangle rect = new Rectangle(, , panel4.Width - cRadius, panel4.Height - cRadius); // 指定图形路径, 有一系列 直线/曲线 组成
GraphicsPath myPath = new GraphicsPath();
myPath.StartFigure();
myPath.AddArc(new Rectangle(new Point(rect.X, rect.Y), new Size( * cRadius, * cRadius)), , );
myPath.AddLine(new Point(rect.X + cRadius, rect.Y), new Point(rect.Right - cRadius, rect.Y));
myPath.AddArc(new Rectangle(new Point(rect.Right - * cRadius, rect.Y), new Size( * cRadius, * cRadius)), , );
myPath.AddLine(new Point(rect.Right, rect.Y + cRadius), new Point(rect.Right, rect.Bottom - cRadius));
myPath.AddArc(new Rectangle(new Point(rect.Right - * cRadius, rect.Bottom - * cRadius), new Size( * cRadius, * cRadius)), , );
myPath.AddLine(new Point(rect.Right - cRadius, rect.Bottom), new Point(rect.X + cRadius, rect.Bottom));
myPath.AddArc(new Rectangle(new Point(rect.X, rect.Bottom - * cRadius), new Size( * cRadius, * cRadius)), , );
myPath.AddLine(new Point(rect.X, rect.Bottom - cRadius), new Point(rect.X, rect.Y + cRadius));
myPath.CloseFigure();
g.DrawPath(new Pen(Color.Red, ), myPath);