첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

#region 라운드 사각형 그리기 - DrawRoundRectangle(graphics, pen, x, y, width, height, radius)

/// <summary>
/// 라운드 사각형 그리기
/// </summary>
/// <param name="graphics">그래픽스</param>
/// <param name="pen">펜</param>
/// <param name="x">X 좌표</param>
/// <param name="y">Y 좌표</param>
/// <param name="width">너비</param>
/// <param name="height">높이</param>
/// <param name="radius">반지름</param>
public void DrawRoundRectangle(Graphics graphics, Pen pen, int x, int y, int width, int height, int radius)
{
    if(width <= 0 || height <= 0)
    {
        return;
    }

    radius = Math.Min(radius, height / 2 - 1);
    radius = Math.Min(radius, width  / 2 - 1);

    if(radius <= 0)
    {
        graphics.DrawRectangle(pen, x, y, width, height);

        return;
    }

    using(GraphicsPath graphicsPath = new GraphicsPath())
    {
        graphicsPath.AddLine(x + radius, y, x + width - (radius * 2), y);
        graphicsPath.AddArc (x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
        graphicsPath.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
        graphicsPath.AddArc (x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
        graphicsPath.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
        graphicsPath.AddArc (x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
        graphicsPath.AddLine(x, y + height - (radius * 2), x, y + radius);
        graphicsPath.AddArc (x, y, radius * 2, radius * 2, 180, 90);

        graphicsPath.CloseFigure();

        graphics.DrawPath(pen, graphicsPath);
    }
}

#endregion

#region 라운드 사각형 그리기 - DrawRoundRectangle(graphics, pen, rectangle, radius)

/// <summary>
/// 라운드 사각형 그리기
/// </summary>
/// <param name="graphics">그래픽스</param>
/// <param name="pen">펜</param>
/// <param name="rectangle">사각형</param>
/// <param name="radius">반지름</param>
public void DrawRoundRectangle(Graphics graphics, Pen pen, Rectangle rectangle, int radius)
{
    DrawRoundRectangle(graphics, pen, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, radius);
}

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요