拖动无边框窗体
#region 本程序中用到的API函数 [DllImport("user32.dll")] public static extern bool ReleaseCapture();//用来释放被当前线程中某个窗口捕获的光标 [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwdn,int wMsg,int mParam,int lParam);//向指定的窗体发送Windows消息 #endregion #region 本程序中需要声明的变量 public const int WM_SYSCOMMAND = 0x0112;//该变量表示将向Windows发送的消息类型 public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息 public const int HTCAPTION = 0x0002;//该变量表示发送消息的附加消息 #endregion private void Frm_Main_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture();//用来释放被当前线程中某个窗口捕获的光标 SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//向Windows发送拖动窗体的消息 }
用到的命名空间:using System.Runtime.InteropServices;