Always handle the PreviewKeyDown event in the base form

We need to handle this event in basic form, regardless of which controls currently have focus. We have a pair of global key teams that should work regardless of the focus of management.

This works by handling the PreviewKeyDown event on the form normally. When we add a user control to the form, the event no longer fires.

Did I miss something trivial here? Or do we need to handle the event in the user element first?

Thank you for your help!

Gratitude factor. When I get more time :) I will earn the "right"!

+2
source share
4 answers

We have finished this:

, , :

ToolStripMenuItem.Visible = false

( ).

, . , whick

+1

, , , , (, Page Up/Page Down), .

, P/Invoke, - Form.KeyPreview true. , , , . OnKeyDown, OnKeyPress / OnKeyUp .

+2

PreviewKeyDown , . , . P/Invoke. SetWindowsHookEx pinvoke.net - . MS KB #, , , .

+1

, , , , .

InitializeComponent(); - :

            foreach (Control control in this.Controls)
            {
                control.PreviewKeyDown += new PreviewKeyDownEventHandler(HandlePreviewKeyDown);
            }

I THINK I have to do the trick. In your HandlePreviewKeyDown method, you can do your job, and it should run regardless of which control has focus.

0
source

All Articles