[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
private void FrmLogin_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
本文介绍了一种使用C#实现窗体拖动的方法。通过调用user32.dll中的API函数ReleaseCapture()和SendMessage(),可以使得窗体在没有传统边框的情况下仍能被拖动。具体实现中,当鼠标按下时触发MouseDown事件,进而释放捕获并发送系统消息以实现拖动。
1万+

被折叠的 条评论
为什么被折叠?



