让普通控件拥有左键移动窗体的功能
如题,代码如下:
/// <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);