How to lock a Form's Location ???

  • Thread starter Thread starter Protege
  • Start date Start date
P

Protege

Hello,

I have a special case where I must lock a form's location (i.e. can't be
moved by user).
I'm guessing that setting some form property or overriding some event(s)
should accomplish this. However, I'm not sure of a good way to do it. Any
ideas?

Thanks, Jeff
 
Hi Jeff,

Override the WndProc of your form and "swallow" all WM_WINDOWPOSCHANGING
messages, that oughtta do it.

Regards,
Alex
 
Hi Alex,

Thanks for your help.
This approach seems like a great idea.
However, its not working for me.
I am seeing and swallowing the WM_WINDOWPOSCHANGING events by overriding the
Form's WndProc method.
However, they must be after the fact, since its not preventing the form from
being moved.
Maybe I should be swallowing some earlier event?

Thanks, Jeff
 
Herfried,

Swallowing these messages works like a champ!
Thanks for your help.

Cheers, Jeff

For those who may want a C# equivalent here is my code:

protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x112;
const int WM_NCLBUTTONDOWN = 0xA1;
const int SC_MOVE = 0xF010;
const int HTCAPTION = 2;

bool ignore = false;

switch (m.Msg)
{
case WM_SYSCOMMAND:
if (m.WParam.ToInt32() == SC_MOVE)
ignore = true;
break;

case WM_NCLBUTTONDOWN:
if (m.WParam.ToInt32() == HTCAPTION)
ignore = true;
break;

default:
break;
}

if (!ignore)
base.WndProc (ref m);
}
 
Back
Top