Hi Patrick,
The easiest way, I believe, is to override WndProc and trap WM_NCHITTEST
message. If the hit happens to fall over the caption just fool the windows
that it is somwhere else (or nowhere). This will stop the form from moving
by the mouse. That was easy. Not so easy, though, is to prevent using Move
command from the system menu. The best is to disable that menu item on the
system menu, but this involves dealing with P\Invoke and Win32 API. The
easiest is to swallow SC_MOVE in the WndProc.
So the code for WndProc, I would suggest, is as follows
private int WM_NCHITTEST = 0x0084;
private int HTCAPTION = 2;
private int HTNOWHERE = 0;
private int WM_SYSCOMMAND = 0x0112;
private int SC_MOVE = 0xF010;
protected override void WndProc(ref Message m)
{
if(m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
if((int)m.Result == HTCAPTION) m.Result = (IntPtr)HTNOWHERE;
return;
}
else if(m.Msg == WM_SYSCOMMAND && (m.WParam.ToInt32() & 0xFFF0) ==
SC_MOVE)
{
//Swallow the move request from the system menu
m.Result = IntPtr.Zero;
return;
}
base.WndProc (ref m);
}
Now the form is pinned.