KeyEventArgs

  • Thread starter Thread starter Arne Garvander
  • Start date Start date
A

Arne Garvander

I know how to capture keys when I am focused on a textbox.
I would like to capture a help key, such as Alt+1, when my focus is on a
arbitrary point on my windows form. How do I do that?
 
Hi Arne,

You need to set KeyPreview = true on the parent form. Any key events sent to
a control will then also be passed to the form's key events (unless the
keypress is cancelled by the control).
 
How do I cancel a key?
--
Arne Garvander
Certified Geek
Professional Data Dude


Morten Wennevik said:
Hi Arne,

You need to set KeyPreview = true on the parent form. Any key events sent to
a control will then also be passed to the form's key events (unless the
keypress is cancelled by the control).

--
Happy Coding!
Morten Wennevik [C# MVP]


Arne Garvander said:
I know how to capture keys when I am focused on a textbox.
I would like to capture a help key, such as Alt+1, when my focus is on a
arbitrary point on my windows form. How do I do that?
 
Arne Garvander said:
How do I cancel a key?


If you set KeyPressEventArgs.Handled = true in a TextBox.KeyPress event that
character won't reach the Text property. That way you can implement numeric
only textboxes and and similar. Similarly, if the Form's KeyPress event
'handles' a character, the child control won't get the KeyPress event.

As for keys handled by the child and not reaching the parent, I'm not sure
how that is implemented, only that the documentations state that this is
possible.
 
Back
Top