#region 可移动
[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;
//在窗体的MouseDown事件里加上代码
private void FrmCheer_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
#endregion
本文提供了一个使用C#实现窗口可拖动功能的代码示例。通过调用user32.dll中的API函数,如ReleaseCapture()和SendMessage(),并在窗体的MouseDown事件中编写特定代码,可以轻松实现窗口的自由移动。
6407

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



