728x90
728x170
▶ MainForm.cs
using System;
using System.Drawing;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 타이머
/// </summary>
private Timer timer;
/// <summary>
/// 난수기
/// </summary>
private Random random;
/// <summary>
/// 임의 값
/// </summary>
private double randomValue;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.timer = new Timer();
this.timer.Interval = 300;
this.random = new Random(DateTime.Now.Millisecond);
Load += Form_Load;
this.timer.Tick += timer_Tick;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
this.timer.Start();
}
#endregion
#region 타이머 틱 처리하기 - timer_Tick(sender, e)
/// <summary>
/// 타이머 틱 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void timer_Tick(object sender, EventArgs e)
{
Point cursorPoint = Cursor.Position;
this.randomValue += this.random.NextDouble() * 2;
if(this.randomValue > 16.28)
{
this.randomValue = 0;
}
Cursor.Position = new Point
(
Convert.ToInt32(cursorPoint.X + (20 * Math.Cos(this.randomValue))),
Convert.ToInt32(cursorPoint.Y + (20 * Math.Sin(this.randomValue)))
);
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] ListView 클래스 : 선택 항목 리스트 구하기 (0) | 2020.06.08 |
---|---|
[C#/WINFORM] Control 클래스 : 컨트롤 비트맵 구하기 (0) | 2020.06.05 |
[C#/WINFORM] Bitmap 클래스 : 회색조 비트맵 구하기 (0) | 2020.06.04 |
[C#/WINFORM/.NETCORE] WinForm .Net Core Class Library 사용하기 (0) | 2020.06.02 |
[C#/WINFORM] Label 클래스 : BackColor 속성을 사용해 투명 배경 설정하기 (0) | 2020.05.27 |
[C#/WINFORM] 윈도우 메시지(Window Message) 상수 (0) | 2020.05.22 |
[C#/WINFORM] Control 클래스 : ProcessCmdKey 메소드를 사용해 CTRL, SHIFT, ALT 조합 키 입력받기 (0) | 2020.05.22 |
[C#/WINFORM] ImmGetConversionStatus API 함수 : 한/영 키 상태 구하기 (0) | 2020.05.22 |
[C#/WINFORM] ManagementClass 클래스 : GetInstances 메소드를 사용해 메모리 사용량 구하기 (0) | 2020.05.22 |
[C#/WINFORM] SendKeys 클래스 : SendWait 정적 메소드를 사용해 화면 캡처하기 (0) | 2020.05.22 |