Preventing a form from resize is its standard option, please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formborderstyle.aspx[
^],
http://msdn.microsoft.com/en-us/library/hw8kes41.aspx[
^].
Four
System.Windows.Forms.FormBorderStyle.Fixed*
members of this enumeration provide options with fixed size.
As to preventing a form to move, it would be a
huge abuse and a crime against the freedom of your users! Just don't do it, ever.
Therefore, your problem is solved without directly messing with message handling.
[EDIT #1]
As to your question, I can explain what's the reason for not getting to the case
WM_KEYDOWN
, but you need to check it up with your code which I cannot see, otherwise it won't be 100% certain.
The thing is: you handle only the messages on your form, but you might also have some controls on your form. One of those controls can possess the keyboard focus. In this case, all keyboard events are handled in this control, so they don't reach your form.
For a test, try same code on empty form, then you will see.
[EDIT #2]
Now, the question is: what to do in practice? You could handle keyboard events on all of your focusable controls as well, but you don't need this complication.
And you don't really need to use
WndProc
to handle keyboard messages. All functionality you possibly can have with those messages, you can by handling some or all of the
System.Windows.Forms.Control
keyboard events:
KeyDown
,
KeyUp
,
KeyPress
and
PreviewKeyDown
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[
^].
You can handle any of these event in the form, without having the problem with a focused child control which can possess the keyboard focus. Now — attention! this is the key point: for this purpose, you should also assign true to the form property
KeyPreview
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx[
^].
I think, by now your question is comprehensively answered.
—SA