C#/Winform
(C#) FormBorderStyle 이 None 인 경우 Form 이동 가능하게 하는 방법
kjun.kr
2017. 7. 28. 00:33
728x90
FomBorderStyle 이 None 인 경우 폼은 마우스로 움직일수가 없다.
그래서 찾아보니 아래처럼 하면 폼을 마우스로 움직일 수가 있다.
만약 Form 위에 Panel 이 올려져 있다면 Panel 에 이벤트를 주면된다.
using System.Runtime.InteropServices;
.....
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
......
private void Form_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
728x90