让窗体不可以拖动

截获消息,当鼠标点在标题栏时,截获消息改为点在窗体上

private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;

protected override void WndProc(ref Message m) {
switch(m.Msg) {
case WM_NCHITTEST:
base.WndProc(ref m);
if ((int)m.Result == HTCAPTION)
m.Result = (IntPtr)HTCLIENT;
return;
break;

}

base.WndProc(ref m);
}

你可能感兴趣的:(让窗体不可以拖动)