本帖最后由 风火石 于 2017-3-16 21:54 编辑
public static GraphicsPath RoundRectPath(float x, float y, float width, float height, int radius) {
GraphicsPath gp = new GraphicsPath();
gp.AddArc(x, y, radius, radius, 180, 90);
gp.AddArc(x + width - radius, y, radius, radius, 270, 90);
gp.AddArc(x + width - radius, y + height - radius, radius, radius, 0, 90);
gp.AddArc(x, y + height - radius, radius, radius, 90, 90);
gp.CloseAllFigures();
return gp;
}
public void DrawRoundRect(Graphics gr, RectangleF rect, int radius)
{
GraphicsPath gp = new GraphicsPath();
gp.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
gp.AddArc(rect.X + rect.Width - radius, rect.Y, radius, radius, 270, 90);
gp.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90);
gp.AddArc(rect.X, rect.Y + rect.Height - radius, radius, radius, 90, 90);
gp.CloseAllFigures();
gr.DrawPath(Pens.Black, gp);
gp.Dispose();
}
|