Gets the line of the rounded rectangle

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();
}
Copy the code

draw

// Create artboard Graphics g = CreateGraphics(); / / clear right to Lear (BackColor); // Line GraphicsPath gp = new GraphicsPath(); DrawRoundRect(gp, 900, 200, 100, 100, 10); G.rawpath (new Pen(color.gray, 2), gp); / / release gp. The Dispose (); g.Dispose();Copy the code

The effect

​​​​

Draw rounded rectangles to fill the interior

DrawPath is just drawing lines. You can fill the interior with FillPath

g.FillPath(Brushes.SkyBlue, gp);
Copy the code

The effect