728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 테스트 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 커서 위치 설정하기 - SetCursorPos(x, y)
/// <summary>
/// 커서 위치 설정하기
/// </summary>
/// <param name="x">X 좌표</param>
/// <param name="y">Y 좌표</param>
/// <returns>처리 결과</returns>
[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
private extern static int SetCursorPos(int x, int y);
#endregion
#region 마우스 이벤트 발생시키기 - mouse_event(flag , deltaX , deltaY , button , extraInformation)
/// <summary>
/// 마우스 이벤트 발생시키기
/// </summary>
/// <param name="flag">플래그</param>
/// <param name="deltaX">델타 X</param>
/// <param name="deltaY">델타 Y</param>
/// <param name="button">버튼</param>
/// <param name="extraInformation">추가 정보</param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "mouse_event")]
private extern static int mouse_event(uint flag , int deltaX , int deltaY , int button , int extraInformation);
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - TestForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 이동하기 버튼 클릭시 처리하기 - moveButton_Click(sender, e)
/// <summary>
/// 이동하기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void moveButton_Click(object sender, EventArgs e)
{
int x = 0;
int y = 0;
int.TryParse(xTextBox.Text, out x);
int.TryParse(yTextBox.Text, out y);
SetCursorPos(x, y);
if(rightButtonCheckBox.Checked)
{
mouse_event((int)MouseFlagType.RIGHTCLICK, x, y, 0, 0);
}
if(leftButtonCheckBox.Checked)
{
mouse_event((int)MouseFlagType.LEFTCLICK, x, y, 0, 0);
}
Text = string.Format("마우스 자동화 (X : {0}, Y : {1}", x, y);
}
#endregion
#region 버튼 체크 상태 변경시 처리하기 - buttonCheckBox_CheckStateChanged(sender, e)
/// <summary>
/// 버튼 체크 상태 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void buttonCheckBox_CheckStateChanged(object sender, EventArgs e)
{
CheckBox checkBox = sender as CheckBox;
if(checkBox.CheckState == CheckState.Checked)
{
if(checkBox == this.leftButtonCheckBox)
{
this.rightButtonCheckBox.CheckState = CheckState.Indeterminate;
}
if(checkBox == this.rightButtonCheckBox)
{
this.leftButtonCheckBox.CheckState = CheckState.Indeterminate;
}
}
if(checkBox.CheckState == CheckState.Unchecked)
{
if(checkBox == this.leftButtonCheckBox)
{
this.rightButtonCheckBox.CheckState = CheckState.Unchecked;
}
if(checkBox == this.rightButtonCheckBox)
{
this.leftButtonCheckBox.CheckState = CheckState.Unchecked;
}
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 시계 컨트롤 사용하기 (0) | 2018.02.01 |
---|---|
[C#/WINFORM] YUV 재생기 사용하기 (0) | 2018.01.31 |
[C#/WINFORM] 화상 키보드 사용하기 (0) | 2018.01.30 |
[C#/WINFORM] Control 클래스 : SetStyle 메소드를 사용해 깜박임 방지하기 (0) | 2018.01.28 |
[C#/WINFORM] 명령 프롬프트를 모방한 콘솔 컨트롤 사용하기 (0) | 2018.01.22 |
[C#/WINFORM] 마우스 자동화 하기 (0) | 2018.01.20 |
[C#/WINFORM] Form 클래스 : InvokeOnClick 메소드를 사용해 컨트롤 클릭하기 (0) | 2018.01.20 |
[C#/WINFORM] SendMessage API를 사용해 컨트롤 클릭하기 (0) | 2018.01.20 |
[C#/WINFORM] 특수 키 상태 조사하기 (0) | 2018.01.17 |
[C#/WINFORM] 로또 컨트롤 사용하기 (0) | 2017.12.18 |
[C#/WINFORM] 바이트 배열에서 폰트 만들기 (0) | 2017.12.16 |
댓글을 달아 주세요