【GDI+】绘制圆角矩形

获取圆角矩形的线

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);

效果

 

 

 

 

相关推荐
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页