Keyboard event propagation in winforms

I have a user control. Inside the user control there is a PictureBox that uses all the properties of the screen (Dock.Fill). I would like to catch keyboard events (e.g. Ctrl-V to implement Paste functionality).

However, there are no key events in the PictureBox. Will the next layer under the PictureBox (i.e. the User Control) receive the KeyUp event? If I add a KeyUp event handler to the user control, will it work? I know that WPF has a routed event solution. How does it work in the world of winforms?

+6
source share
2 answers

You can receive the event in the form. See Form.KeyPreview .

If this property is set to true, the form will receive all KeyPress, KeyDown, and KeyUp events. After the event handlers of the form have finished processing the keystroke, the keystroke is then assigned to the control with focus

+4
source

Source: https://habr.com/ru/post/926504/


All Articles