728x90
728x170
▶ MainForm.cs
using System.Drawing;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 이벤트를 설정한다.
Paint += Form_Paint;
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 페인트시 처리하기 - Form_Paint(sender, e)
/// <summary>
/// 폼 페인트시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Paint(object sender, PaintEventArgs e)
{
const int gap = 8;
const int rowCount = 4;
int width = DisplayRectangle.Width / rowCount;
int height = DisplayRectangle.Height / rowCount;
for(int x = 0; x < rowCount; x++)
{
for(int y = 0; y < rowCount; y++)
{
DrawBorder
(
e.Graphics,
new Rectangle
(
x * width + gap / 2,
y * height + gap / 2,
width - gap,
height - gap
),
BorderStyle.Fixed3D,
y == x
);
}
}
DrawBorder(e.Graphics, DisplayRectangle, BorderStyle.Fixed3D);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 테두리 그리기 - DrawBorder(graphics, rectangle, borderStyle, sunken)
/// <summary>
/// 테두리 그리기
/// </summary>
/// <param name="graphics">그래픽스</param>
/// <param name="rectangle">사각형</param>
/// <param name="borderStyle">테두리 스타일</param>
/// <param name="sunken">함몰 여부</param>
private void DrawBorder(Graphics graphics, Rectangle rectangle, BorderStyle borderStyle, bool sunken)
{
if(borderStyle == BorderStyle.FixedSingle)
{
rectangle.Width -= 1;
rectangle.Height -= 1;
graphics.DrawRectangle(Pens.Black, rectangle);
}
else if(borderStyle == BorderStyle.Fixed3D)
{
Color[] colorArray;
if(sunken)
{
colorArray = new Color[]
{
SystemColors.ControlDark,
SystemColors.ControlDarkDark,
SystemColors.ControlLightLight,
SystemColors.ControlLight
};
}
else
{
colorArray = new Color[]
{
SystemColors.ControlLightLight,
SystemColors.ControlLight,
SystemColors.ControlDark,
SystemColors.ControlDarkDark
};
}
using(Pen pen = new Pen(colorArray[0]))
{
graphics.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.X , rectangle.Y);
graphics.DrawLine(pen, rectangle.X, rectangle.Y , rectangle.Right - 1, rectangle.Y);
}
using(Pen pen = new Pen(colorArray[1]))
{
graphics.DrawLine(pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.X + 1 , rectangle.Y + 1);
graphics.DrawLine(pen, rectangle.X + 1, rectangle.Y + 1 , rectangle.Right - 2, rectangle.Y + 1);
}
using(Pen pen = new Pen(colorArray[2]))
{
graphics.DrawLine(pen, rectangle.X , rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1);
graphics.DrawLine(pen, rectangle.Right - 1, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Y );
}
using(Pen pen = new Pen(colorArray[3]))
{
graphics.DrawLine(pen, rectangle.X + 1 , rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2);
graphics.DrawLine(pen, rectangle.Right - 2, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Y + 1 );
}
}
}
#endregion
#region 테두리 그리기 - DrawBorder(graphics, rectangle, borderStyle)
/// <summary>
/// 테두리 그리기
/// </summary>
/// <param name="graphics">그래픽스</param>
/// <param name="rectangle">사각형</param>
/// <param name="borderStyle">테두리 스타일</param>
private void DrawBorder(Graphics graphics, Rectangle rectangle, BorderStyle borderStyle)
{
DrawBorder(graphics, rectangle, borderStyle, true);
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 문단 JUSTIFY 정렬하기 (0) | 2018.12.16 |
---|---|
[C#/WINFORM] 문자열 JUSTIFY 정렬하기 (0) | 2018.12.16 |
[C#/WINFORM] 다각형 에디터 사용하기 (0) | 2018.12.13 |
[C#/WINFORM] 라인 에디터 사용하기 (0) | 2018.12.13 |
[C#/WINFORM] 확대 창 사용하기 (0) | 2018.12.13 |
[C#/WINFORM] 소수 프랙탈(Prime Number Fractal) 그리기 (0) | 2018.12.11 |
[C#/WINFORM] PictureBox 클래스 : 이미지 드래그 하기 (0) | 2018.12.11 |
[C#/WINFORM] Region 클래스 : 특정 모양을 갖는 폼 만들기 (0) | 2018.12.10 |
[C#/WINFORM] TextureBrush 클래스 사용하기 (0) | 2018.12.10 |
[C#/WINFORM] 영역 채우기(Flood Fill) (0) | 2018.12.10 |