-
C# 폼 이동 방법프로그래밍/C# 2016. 7. 19. 18:53
폼의 타이틀을 없앴거나 타이틀 외에도 다른 부분을 클릭해서 폼을 움직이게하고자 한다면
아래와 같이 코딩하면 된다.
private bool onDrag = false;
private Point point0;
private void frmMain_MouseDown(object sender, MouseEventArgs e)
{
this.onDrag = true;
this.point0 = new Point(e.X, e.Y);
}
private void frmMain_MouseMove(object sender, MouseEventArgs e)
{
if (this.onDrag == false) return;
int x0 = this.Location.X;
int y0 = this.Location.Y;
int dx = e.X - this.point0.X;
int dy = e.Y - this.point0.Y;
this.Location = new Point(x0 + dx, y0 + dy);
}
private void frmMain_MouseUp(object sender, MouseEventArgs e)
{
this.onDrag = false;
}
'프로그래밍 > C#' 카테고리의 다른 글
C# 현재위치(경로) 가져오는 방법 (0) 2016.08.16 C# Font 사이즈 컨트롤 크기에 맞게 자동조절 (0) 2016.08.12 C# 폼 이동 방법 (0) 2016.07.19 C# WindowsForm에서 배경 투명하게 하는 방법 (0) 2016.07.19 C# Resources에서 이미지 파일 불러오기 (0) 2016.07.19 C# string을 DateTime으로 변환 (0) 2016.07.05 TAG