winform 窗口移动

问题:登陆窗口能够用鼠标拖动

解决:在网上找到代码解决问题

添加using System.Runtime.InteropServices;命名空间,然后在登陆窗口中添加如下代码

[DllImport("user32.dll")]
public static extern bool ReleaseCapture();

[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwdn, int wMsg, int mParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;

//在窗口的MouseDown事件中调用方法

private void fmLogin_MouseDown(object sender, MouseEventArgs e)
{
     ReleaseCapture();
     SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}

你可能感兴趣的:(object,user,WinForm)