在winform程序中,有時會選擇邊框設計會none,但是這樣就不能拖拽窗體移動
解決方案有二;
1,判斷座標控制拖拽
2.利用API函數,
下面介紹利用API函數,方便,快捷
#region 移動無邊框窗體事件
private void form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//*********************調用移動無窗體控件函數
}
#endregion
#region 拖動無邊框窗體
[DllImport("user32.dll")]//*********************拖動無窗體的控件
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
#endregion
這樣就能輕鬆實現窗體拖拽!