Quote:
> I try to catch and handle all keyinputs of a form in a sub.
> Therefore I set the forms KeyPreview property to True and
> everything works well. But when a ButtonControl on the form
> holds the focus, neither the Form1_KeyPress nor the
> Form1_KeyDown gets fired, when the Enter-key ist pressed. All
> other keys work as expected.
> I would like to know, if this behaviour is a bug or if it is by
> design. Is there a workaround?
It's by design. The enter key is as "command key". You can overwrite
ProcessCmdKey to handle it:
Protected Overrides Function ProcessCmdKey( _
ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) _
As Boolean
If keyData = Keys.Enter Then
Debug.WriteLine("enter pressed")
Return True
End If
End Function
Whether you have to Return True depends (see docs for
ProcessCmdKey)
Armin