在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
这样就能轻松实现窗体拖拽!