728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 마진
/// </summary>
private const int MARGIN = 10;
/// <summary>
/// 중심 X
/// </summary>
private int centerX;
/// <summary>
/// 중심 Y
/// </summary>
private int centerY;
/// <summary>
/// 너비
/// </summary>
private int width;
/// <summary>
/// 높이
/// </summary>
private int height;
/// <summary>
/// 포인트 리스트
/// </summary>
private List<PointF> pointList = null;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
ResizeRedraw = true;
#region 이벤트를 설정한다.
Load += Form_Load;
Resize += Form_Resize;
Paint += Form_Paint;
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
SetDrawingObject();
}
#endregion
#region 폼 크기 조정시 처리하기 - Form_Resize(sender, e)
/// <summary>
/// 폼 크기 조정시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Resize(object sender, EventArgs e)
{
SetDrawingObject();
}
#endregion
#region 폼 페인트시 처리하기 - Form_Paint(sender, e)
/// <summary>
/// 폼 페인트시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Paint(object sender, PaintEventArgs e)
{
if((this.width <= 0) || (this.height <= 0))
{
return;
}
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.FillEllipse(Brushes.LightBlue, MARGIN, MARGIN, this.width, this.height);
e.Graphics.DrawEllipse(Pens.Blue, MARGIN, MARGIN, this.width, this.height);
e.Graphics.DrawLines(Pens.Blue, this.pointList.ToArray());
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 그리기 객체 설정하기 - SetDrawingObject()
/// <summary>
/// 그리기 객체 설정하기
/// </summary>
private void SetDrawingObject()
{
this.width = ClientSize.Width - 2 * MARGIN;
this.height = ClientSize.Height - 2 * MARGIN;
this.centerX = ClientSize.Width / 2;
this.centerY = ClientSize.Height / 2;
Random random = new Random();
double circumference = 2 * Math.PI * Math.Sqrt((this.width * this.width + this.height * this.height) / 2);
int pointCount = (int)(circumference / 40);
this.pointList = new List<PointF>();
for(int i = 0; i < pointCount; i++)
{
double theta1 = 2 * Math.PI * random.NextDouble();
float x1 = (float)(this.centerX + Math.Cos(theta1) * this.width / 2);
float y1 = (float)(this.centerY + Math.Sin(theta1) * this.height / 2);
this.pointList.Add(new PointF(x1, y1));
double theta2 = 2 * Math.PI * random.NextDouble();
float x2 = (float)(this.centerX + Math.Cos(theta2) * this.width / 2);
float y2 = (float)(this.centerY + Math.Sin(theta2) * this.height / 2);
this.pointList.Add(new PointF(x2, y2));
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] Graphics 클래스 : DrawString 메소드를 사용해 양쪽 맞춤 텍스트 그리기 (0) | 2019.01.07 |
---|---|
[C#/WINFORM] 이미지 거리 측정하기 (0) | 2019.01.07 |
[C#/WINFORM] 콤보 박스/리스트 박스 데이터 소스 연결하기 (0) | 2019.01.07 |
[C#/WINFORM] 바퀴와 연결된 2개의 막대 움직이기 (0) | 2019.01.07 |
[C#/WINFORM] 로봇 팔 마우스 추적하기 (0) | 2019.01.07 |
[C#/WINFORM] RichTextBox 클래스 : 위/아래 첨자 사용하기 (0) | 2019.01.06 |
[C#/WINFORM] Graphics 클래스 : MeasureString 메소드를 사용해 텍스트 그리기 (0) | 2019.01.06 |
[C#/WINFORM] WebBrowser 클래스 : 구글 맵 사용하기 (0) | 2019.01.06 |
[C#/WINFORM] Metafile 클래스 : 메타 파일 기록 열거하기 (0) | 2019.01.06 |
[C#/WINFORM] Metafile 클래스 : 메타 파일 로드하기 (0) | 2019.01.06 |
댓글을 달아 주세요