17
境界線を持つ丸い四角形を描画する方法があります。境界線はどのような幅でもかまいません。問題は、境界線がパスの中心から引き出されているため、境界線が太いときに境界線を越えて延びていることです。特定の境界内に可変幅の境界線を持つ丸みのある四角形を描画する方法
境界線の幅を指定して境界に完全に収まるようにするにはどうすればよいですか?
ここに丸い四角形を描画するために使用しているコードを示します。
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);
}