[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 Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
本文介绍了一种使用 C# 在 Windows 应用程序中实现窗口拖动的方法。通过调用 user32.dll 中的 ReleaseCapture 和 SendMessage 函数,并定义特定的消息参数 WM_SYSCOMMAND、SC_MOVE 和 HTCAPTION,可以实现在鼠标按下时开始拖动窗口的功能。
6473

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



