1

I have a C# WinForm application. On the main form, I have a user control. What I want to be able to do is, whenever a key is pressed on the keyboard, I would like to have my user control receive the keyboard input, so that the keyboard related events (KeyDown, KeyUp and KeyPress) all fire inside the one specific user control.

I would like the actual main form and any other user control on the form to ignore the keypress. Is this possible?

Icemanind
  • 47,519
  • 50
  • 171
  • 296

1 Answers1

0

You can do this by ensuring that your control always has focus. An easy way is in the Control.LostFocus event set the focus back. The UserControls base class isn't great about recieving focus, so instead you may want to pick a control within your user control to always have focus and receive events.

Mathieson
  • 1,698
  • 2
  • 17
  • 19