首页 > 代码库 > FormBorderStyle为None的时候如何拖动窗体

FormBorderStyle为None的时候如何拖动窗体

 

 1 //为DllImport导出命名空间, 2 using System.Runtime.InteropServices; 3 public partial class Form1 : System.Windows.Forms.Form 4 { 5 #region FormBorderStyle为None,拖放窗体 6 [DllImport("user32.dll")] 7 public static extern bool ReleaseCapture(); 8 [DllImport("user32.dll")] 9 public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);10 public const int WM_SYSCOMMAND = 0x0112;11 public const int SC_MOVE = 0xF010;12 public const int HTCAPTION = 0x0002;13 private void Form_MouseDown(object sender, MouseEventArgs e)14 {15 ReleaseCapture();16 SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);17 }18 #endregion19 #region 构造函数20 public Form1()21 {22 //初始化窗体信息23 //InitializeComponent();24 //绑定鼠标拖动窗体事件25 this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form_MouseDown);26 }27 #endregion28 }
View Code

 

参考: 

http://www.dxper.net/thread-2525-1-1.html
http://www.cnblogs.com/rogation/p/3508266.html
DllImport:http://blog.csdn.net/jame_peng/article/details/4387906