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
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 커서 배열
/// </summary>
private Cursor[] cursorArray;
/// <summary>
/// 커서 카운트
/// </summary>
private const int CURSOR_COUNT = 18;
/// <summary>
/// 현재 커서 인덱스
/// </summary>
private int currentCursorIndex = 0;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 이벤트를 설정한다.
Load += Form_Load;
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)
{
const int CURSOR_WIDTH = 32;
const int CURSOR_HEIGHT = 32;
float centetX = CURSOR_WIDTH / 2f;
float centerY = CURSOR_HEIGHT / 2f;
float radiusX = centetX * 0.9f;
float radiusY = centetX * 0.4f;
RectangleF rectangle = new RectangleF(-radiusX, -radiusY, 2 * radiusX, 2 * radiusY);
float radius = centetX * 0.15f;
Matrix transform1 = new Matrix();
transform1.Rotate(60f, MatrixOrder.Append);
transform1.Translate(centetX, centerY, MatrixOrder.Append);
Matrix transform2 = new Matrix();
transform2.Rotate(-60f, MatrixOrder.Append);
transform2.Translate(centetX, centerY, MatrixOrder.Append);
Matrix transform3 = new Matrix();
transform3.Translate(centetX, centerY, MatrixOrder.Append);
Bitmap sourceBitmap = new Bitmap(CURSOR_WIDTH, CURSOR_HEIGHT);
using(Graphics sourceGraphics = Graphics.FromImage(sourceBitmap))
{
sourceGraphics.SmoothingMode = SmoothingMode.AntiAlias;
sourceGraphics.Clear(Color.Transparent);
sourceGraphics.Transform = transform1;
sourceGraphics.DrawEllipse(Pens.Red, rectangle);
sourceGraphics.Transform = transform2;
sourceGraphics.DrawEllipse(Pens.Red, rectangle);
sourceGraphics.Transform = transform3;
sourceGraphics.DrawEllipse(Pens.Red, rectangle);
sourceGraphics.FillEllipse(Brushes.Black, -radius, -radius, 2 * radius, 2 * radius);
}
this.cursorArray = new Cursor[CURSOR_COUNT];
double theta1 = 0;
double dtheta1 = 2 * Math.PI / CURSOR_COUNT;
double theta2 = 0;
double dtheta2 = 2 * Math.PI / CURSOR_COUNT * 2;
double theta3 = 0;
double dtheta3 = 2 * Math.PI / CURSOR_COUNT * 3;
for(int i = 0; i < CURSOR_COUNT; i++)
{
Bitmap cursorBitmap = new Bitmap(CURSOR_WIDTH, CURSOR_HEIGHT);
using(Graphics cursorGraphics = Graphics.FromImage(cursorBitmap))
{
cursorGraphics.SmoothingMode = SmoothingMode.AntiAlias;
cursorGraphics.DrawImage(sourceBitmap, 0, 0);
cursorGraphics.Transform = transform1;
double x1 = radiusX * Math.Cos(theta1);
double y1 = radiusY * Math.Sin(theta1);
cursorGraphics.FillEllipse(Brushes.Red, (int)(x1 - radius), (int)(y1 - radius), 2 * radius, 2 * radius);
theta1 += dtheta1;
cursorGraphics.Transform = transform2;
double x2 = radiusX * Math.Cos(theta2);
double y2 = radiusY * Math.Sin(theta2);
cursorGraphics.FillEllipse(Brushes.Green, (int)(x2 - radius), (int)(y2 - radius), 2 * radius, 2 * radius);
theta2 += dtheta2;
cursorGraphics.Transform = transform3;
double x3 = radiusX * Math.Cos(theta3);
double y3 = radiusY * Math.Sin(theta3);
cursorGraphics.FillEllipse(Brushes.Blue, (int)(x3 - radius), (int)(y3 - radius), 2 * radius, 2 * radius);
theta3 += dtheta3;
}
this.cursorArray[i] = new Cursor(cursorBitmap.GetHicon());
theta1 += dtheta1;
}
}
#endregion
#region 타이머 틱 처리하기 - timer_Tick(sender, e)
/// <summary>
/// 타이머 틱 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void timer_Tick(object sender, EventArgs e)
{
this.currentCursorIndex = (this.currentCursorIndex + 1) % CURSOR_COUNT;
Cursor = this.cursorArray[this.currentCursorIndex];
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 레이블을 갖는 히스토그램 그리기 (0) | 2019.01.14 |
---|---|
[C#/WINFORM] 장미 곡선(Rose Curve) 그리기 (0) | 2019.01.14 |
[C#/WINFORM] 테오 스파이럴(Spiral of Theodorus) 그리기 (0) | 2019.01.14 |
[C#/WINFORM] 피타고라스 나무 프랙탈(Pythagorean Tree Fractal) 그리기 (0) | 2019.01.14 |
[C#/WINFORM] 시어핀스키 펜타곤(Sierpinski Pentagon) 그리기 (0) | 2019.01.14 |
[C#/WINFORM] ListView 클래스 : 커스텀 아이콘 사용하기 (0) | 2019.01.14 |
[C#/WINFORM] Cursor 클래스 : 사용자 정의 커서 사용하기 (0) | 2019.01.14 |
[C#/WINFORM] 사용자가 스크롤바 최대값을 선택할 수 있게 하기 (0) | 2019.01.14 |
[C#/WINFORM] StringFormat 클래스 : Alignment 속성을 사용해 문자열 정렬하기 (0) | 2019.01.14 |
[C#/WINFORM] StringFormat 클래스 : SetTabStops 메소드를 사용해 탭 설정하기 (0) | 2019.01.14 |