C# 无边框窗体的移动的实现其实很简单,只要将点击窗体事件修改为点击窗体标题栏事件。但是这样会有个缺电,双击窗体时最大化。下面是全部实现代码,可以移动,并且不会最大化。
internal static int WM_NCHITTEST = 0x84;
internal static IntPtr HTCLIENT = (IntPtr)0x1;
internal static IntPtr HTCAPTION = (IntPtr)0x2;
internal static int WM_NCLBUTTONDBLCLK = 0x00A3;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCLBUTTONDBLCLK)
{
return;
}
if (m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
if (m.Result == HTCLIENT)
{
m.HWnd = this.Handle;
m.Result = HTCAPTION;
}
return;
}
base.WndProc(ref m);
}
internal static int WM_NCHITTEST = 0x84;
internal static IntPtr HTCLIENT = (IntPtr)0x1;
internal static IntPtr HTCAPTION = (IntPtr)0x2;
internal static int WM_NCLBUTTONDBLCLK = 0x00A3;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCLBUTTONDBLCLK)
{
return;
}
if (m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
if (m.Result == HTCLIENT)
{
m.HWnd = this.Handle;
m.Result = HTCAPTION;
}
return;
}
base.WndProc(ref m);
}