黄聪:C# 窗体拖拽功能

#region - 拖拽功能实现Dll -
[Description("使能拖拽功能.")]
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
#endregion

 

public Form1()
{
   this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Window_CanDrap);

}

 

private void Window_CanDrap(object sender, MouseEventArgs e)
{
      const int WM_NCLBUTTONDOWN = 0x00A1;
      const int HT_CAPTION = 0x0002;
      ReleaseCapture();
      //传递左键按下事件
      SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}

原文地址:https://www.cnblogs.com/huangcong/p/1697077.html