728x90
반응형
728x170
▶ MainForm.cs
using System.Drawing;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 첫번째 포인트
/// </summary>
private Point firstPoint = new Point();
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.panel.MouseDown += panel_MouseDown;
this.panel.MouseMove += panel_MouseMove;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 패널 마우스 DOWN 처리하기 - panel_MouseDown(sender, e)
/// <summary>
/// 패널 마우스 DOWN 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void panel_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
this.firstPoint = Control.MousePosition;
}
}
#endregion
#region 패널 마우스 이동시 처리하기 - panel_MouseMove(sender, e)
/// <summary>
/// 패널 마우스 이동시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void panel_MouseMove(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
Point mousePoint = Control.MousePosition;
Point deltaPoint = new Point
(
this.firstPoint.X - mousePoint.X,
this.firstPoint.Y - mousePoint.Y
);
this.panel.Location = new Point
(
this.panel.Location.X - deltaPoint.X,
this.panel.Location.Y - deltaPoint.Y
);
this.firstPoint = mousePoint;
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 마우스/키보드 후킹하기 (0) | 2020.09.23 |
---|---|
[C#/WINFORM] TextBox 클래스 : KeyPress 이벤트를 사용해 숫자 입력시 자동으로 콤마 출력하기 (0) | 2020.09.18 |
[C#/WINFORM] Control 클래스 : 로딩 패널 사용하기 (0) | 2020.09.14 |
[C#/WINFORM] PrinterSettings 클래스 : InstalledPrinters 정적 속성을 사용해 설치 프린터 리스트 구하기 (0) | 2020.08.26 |
[C#/WINFORM] Form 클래스 : TopLevel 속성을 사용해 Form 객체를 컨트롤처럼 사용하기 (0) | 2020.08.26 |
[C#/WINFORM] Panel 클래스 : MouseDown/MouseMove 이벤트를 사용해 이동시키기 (0) | 2020.08.25 |
[C#/WINFORM] Icon 클래스 : 파일에서 아이콘 파일 만들기 (0) | 2020.08.10 |
[C#/WINFORM] Icon 클래스 : 아이콘 파일 만들기 (0) | 2020.08.10 |
[C#/WINFORM] Graphics 클래스 : FillPath/DrawPath 메소드를 사용해 라운드 사각형 그리기 (0) | 2020.08.10 |
[C#/WINFORM] Graphics 클래스 : DrawRectangle 메소드를 사용해 사각형 그리기 (0) | 2020.08.10 |
[C#/WINFORM] Bitmap 클래스 : 비트맵 바이트 배열 구하기 (0) | 2020.08.10 |
댓글을 달아 주세요