【发布时间】:2010-10-12 07:28:59
【问题描述】:
我有一个方法可以绘制一个带边框的圆角矩形。边框可以是任何宽度,所以我遇到的问题是当边框很厚时,它会超出给定的边界,因为它是从路径的中心绘制的。
如何包含边框的宽度以使其完全适合给定的边界?
这是我用来绘制圆角矩形的代码。
private void DrawRoundedRectangle(Graphics gfx, Rectangle Bounds, int CornerRadius, Pen DrawPen, Color FillColor)
{
GraphicsPath gfxPath = new GraphicsPath();
DrawPen.EndCap = DrawPen.StartCap = LineCap.Round;
gfxPath.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90);
gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90);
gfxPath.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
gfxPath.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
gfxPath.CloseAllFigures();
gfx.FillPath(new SolidBrush(FillColor), gfxPath);
gfx.DrawPath(DrawPen, gfxPath);
}
【问题讨论】:
标签: c# gdi+ rounded-corners