通过调用API函数实现的无边框窗体的拖拽,比判断坐标更快捷
在winform程序中,有时会选择边框设计会none,但是这样就不能拖拽窗体移动
解决方案有二;
1,判断坐标控制拖拽
2.利用API函数,
下面介绍利用API函数,方便,快捷
#region 移动无边框窗体事件 private void form1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//*********************调用移动无窗体控件函数 } #endregion #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; #endregion
这样就能轻松实现窗体拖拽!
作者:Joe.Fan
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。