728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 코너 포인트 리스트
/// </summary>
private List<PointF> cornerPointList;
/// <summary>
/// 마지막 포인트
/// </summary>
private PointF lastPoint;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 이벤트를 설정한다.
Load += Form_Load;
Resize += Form_Resize;
this.timer.Tick += timer_Tick;
#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)
{
DefineCorner();
}
#endregion
#region 폼 크기 조정시 처리하기 - Form_Resize(sender, e)
/// <summary>
/// 폼 크기 조정시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Resize(object sender, EventArgs e)
{
DefineCorner();
using(Graphics graphics = CreateGraphics())
{
graphics.Clear(BackColor);
}
}
#endregion
#region 타이머 틱 처리하기 - timer_Tick(sender, e)
/// <summary>
/// 타이머 틱 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void timer_Tick(object sender, EventArgs e)
{
Random random = new Random();
using(Graphics graphics = CreateGraphics())
{
foreach(PointF cornerPoint in this.cornerPointList)
{
graphics.FillEllipse(Brushes.White, cornerPoint.X - 2, cornerPoint.Y - 2, 4, 4);
graphics.DrawEllipse(Pens.Blue, cornerPoint.X - 2, cornerPoint.Y - 2, 4, 4);
}
for(int i = 1; i <= 1000; i++)
{
int j = random.Next(0, 3);
this.lastPoint = new PointF
(
(this.lastPoint.X + this.cornerPointList[j].X) / 2,
(this.lastPoint.Y + this.cornerPointList[j].Y) / 2
);
graphics.DrawLine
(
Pens.Red,
this.lastPoint.X,
this.lastPoint.Y,
this.lastPoint.X + 1,
this.lastPoint.Y + 1
);
}
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 코너 정의하기 - DefineCorner()
/// <summary>
/// 코너 정의하기
/// </summary>
private void DefineCorner()
{
this.cornerPointList = new List<PointF>();
this.cornerPointList.Add(new PointF(ClientSize.Width / 2, 10));
this.cornerPointList.Add(new PointF(10, ClientSize.Height - 10));
this.cornerPointList.Add(new PointF(ClientSize.Width - 10, ClientSize.Height - 10));
this.lastPoint = this.cornerPointList[0];
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] Region 클래스 : 특정 모양을 갖는 폼 만들기 (0) | 2018.12.10 |
---|---|
[C#/WINFORM] TextureBrush 클래스 사용하기 (0) | 2018.12.10 |
[C#/WINFORM] 영역 채우기(Flood Fill) (0) | 2018.12.10 |
[C#/WINFORM] 유니코드 문자 조회하기 (0) | 2018.12.09 |
[C#/WINFORM] 움직이는 GIF 이미지 사용하기 (0) | 2018.12.09 |
[C#/WINFORM] 원과 원의 교차 여부 구하기 (0) | 2018.12.09 |
[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 |
댓글을 달아 주세요