C# Winform 让整个窗口都可以拖动
调用Windows API:
[DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); private void frmMain_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, 0x0112, 0xF012, 0); }
调用方法:重写当前窗体的鼠标按下去的事件:
protected override void OnMouseDown(MouseEventArgs e);
示例如下:
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); frmMain_MouseDown(this, e); }
这样,当拖动窗体空白区域时这个窗体就可以拖动了。
本博客内容,如需转载请务必保留超链接。Contact Me:Mail此处省略好几个字...