ibcadmin 发表于 2017-4-17 08:50:46

Win32函数实现鼠标拖动窗口


private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

private static extern bool ReleaseCapture();
private const uint WM_SYSCOMMAND = 0x0112;
private const int WM_SETREDRAW = 11;
private const int SC_MOVE = 61456;
private const int HTCAPTION = 2;
public static voidMoveWindow(IntPtr handle)
{
      ReleaseCapture();
      SendMessage(handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 5);
}

要实现鼠标点击拖动,只需要在鼠标MouseDown事件中 调用MoveWindow方法即可,参数传入窗口句柄。

private void XXXX_MouseDown(object sender, MouseEventArgs e)
{
   MoveWindow(XXXX.Handle);
}

ibcadmin 发表于 2017-4-17 08:51:12

叶叶叶

Amy尾巴 发表于 2017-4-17 09:27:12

666
页: [1]
查看完整版本: Win32函数实现鼠标拖动窗口