如題,程式碼如下:
/// <summary>設定可以滑鼠左鍵讓窗體移動的控制元件 /// </summary> /// <param name="form">待移動的窗體,通常是設定了FormBorderStyle = FormBorderStyle.None的窗體</param> /// <param name="control">能控制窗體左鍵移動的控制元件</param> public static void SetMoveFormControl(Form form, Control control) { control.MouseDown += (s, e) => { ReleaseCapture(); SendMessageA((int)form.Handle, 0xa1, 2, 0); }; } [DllImport("user32.dll")] private static extern int ReleaseCapture(); [DllImport("user32.dll")] private static extern int SendMessageA(int hwnd, int wMsg, int wParam, int lParam);