窗體定義操作系統(tǒng)自帶api方法:
#region 鼠標(biāo)左鍵移動(dòng)窗體
? ? ? ? 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();
? ? ? ? #endregion
窗體鼠標(biāo)mousedown事件實(shí)現(xiàn)以下代碼:
if (e.Button == MouseButtons.Left)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ReleaseCapture();
? ? ? ? ? ? ? ? SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
? ? ? ? ? ? }