728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
ResizeRedraw = true;
#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)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
int width = (int)(ClientRectangle.Width * 0.9);
int height = (int)(ClientRectangle.Height * 0.9);
int size = (width > height) ? height : width;
Rectangle rectangle = new Rectangle((int)((ClientRectangle.Width - size) / 2d), (int)((ClientRectangle.Height - size) / 2d), size, size);
PointF[] pointArray = GetStarPointArray(5, rectangle);
e.Graphics.DrawPolygon(Pens.Blue, pointArray);
e.Graphics.DrawRectangle(Pens.Red, rectangle);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 스타 포인트 배열 구하기 - GetStarPointArray(vertexCount, boundRectangle)
/// <summary>
/// 스타 포인트 배열 구하기
/// </summary>
/// <param name="vertexCount">꼭지점 카운트</param>
/// <param name="boundRectangle">테두리 사각형</param>
/// <returns>스타 포인트 배열</returns>
private PointF[] GetStarPointArray(int vertexCount, Rectangle boundRectangle)
{
PointF[] pointArray = new PointF[2 * vertexCount];
double rx1 = boundRectangle.Width / 2;
double ry1 = boundRectangle.Height / 2;
double rx2 = rx1 * 0.5;
double ry2 = ry1 * 0.5;
double cx = boundRectangle.X + rx1;
double cy = boundRectangle.Y + ry1;
double theta = -Math.PI / 2;
double dtheta = Math.PI / vertexCount;
for(int i = 0; i < 2 * vertexCount; i += 2)
{
pointArray[i] = new PointF
(
(float)(cx + rx1 * Math.Cos(theta)),
(float)(cy + ry1 * Math.Sin(theta))
);
theta += dtheta;
pointArray[i + 1] = new PointF
(
(float)(cx + rx2 * Math.Cos(theta)),
(float)(cy + ry2 * Math.Sin(theta))
);
theta += dtheta;
}
return pointArray;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 직선과 원의 교차 여부 구하기 (0) | 2018.12.09 |
---|---|
[C#/WINFORM] 타원 버튼 그리기 (0) | 2018.12.09 |
[C#/WINFORM] 피코버 별난 끌개 프랙탈(Pickover Strange Attractor Fractal) 그리기 (0) | 2018.12.09 |
[C#/WINFORM] Graphics 클래스 : TextRenderingHint 속성을 사용해 폰트 안티-알리아싱 설정하기 (0) | 2018.12.09 |
[C#/WINFORM] PathGradientBrush 클래스 사용하기 (0) | 2018.12.09 |
[C#/WINFORM] GroupBox 클래스 : 체크 그룹 박스 사용하기 (0) | 2018.12.09 |
[C#/WINFORM] ToolStripButton 클래스 : 라디오 버튼 사용하기 (0) | 2018.12.09 |
[C#/WINFORM] ListView 클래스 : 그룹 사용하기 (0) | 2018.12.08 |
[C#/WINFORM] 임의의 선으로 채워진 텍스트 그리기 (0) | 2018.12.08 |
[C#/WINFORM] 외곽선 텍스트 그리기 (0) | 2018.12.08 |
댓글을 달아 주세요