Home All Groups Group Topic Archive Search About

Catch Key Down Event anywhere on Windows Form

Author
18 Nov 2006 4:05 PM
Ben
Hi

I would like to complete a task whenever F4 is pressed by the user anywhere
on a form.

The problem is the Key Down event does not fire for the form if the user is,
for example within a text box.  Is there any method of doing this other than
adding the code to the key down event for all controls?

Thanks
B

Author
18 Nov 2006 4:51 PM
Ken Tucker [MVP]
Hi,

        If you set the forms keypreview property to true the form will get
the keydown before the textbox.
http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx

Ken
--------------------------

Show quoteHide quote
"Ben" wrote:

> Hi
>
> I would like to complete a task whenever F4 is pressed by the user anywhere
> on a form.
>
> The problem is the Key Down event does not fire for the form if the user is,
> for example within a text box.  Is there any method of doing this other than
> adding the code to the key down event for all controls?
>
> Thanks
> B
>
>
>