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