如题,代码如下:
/// <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);
时间: 2024-10-25 15:55:04