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
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 포인트 크기 구하기 (0) | 2015.02.01 |
---|---|
[C#/WINFORM] 폰트 패밀리 구하기 (0) | 2015.02.01 |
[C#/WINFORM] 다각형 그리기 (0) | 2015.02.01 |
[C#/WINFORM] 선 그리기 (0) | 2015.02.01 |
[C#/WINFORM] 라운드 사각형 칠하기 (0) | 2015.02.01 |
[C#/WINFORM] 사각형 그리기 (0) | 2015.02.01 |
[C#/WINFORM] 사각형 칠하기 (0) | 2015.02.01 |
[C#/WINFORM] 원에서 특정 각도 포인트 구하기 (0) | 2015.01.31 |
[C#/WINFORM] 범위 색상 구하기 (0) | 2015.01.31 |
[C#/WINFORM] 비슷한 색상 구하기 (0) | 2015.01.31 |