Trap keyboard events on a user control

flynn

Regular
Joined
Jul 28, 2005
Messages
59
The ESCAPE key can be trapped on a form by setting the "KeyPreview" property to true, but the user control does not have this property. Does anyone know how to trap a specific key on a user control, no matter what control on that user control has the focus?

I need this functionality so that if the user presses the ESCAPE key, I can hide the user control until it is needed later.

I'm guessing that a user control is treated exactly the same as a textbox control (or other control) in that there is no KeyPreview for those controls. I suppose I'll have to trap the ESCAPE key on the Form that contains the user control, then act accordingly, correct?

tia,
flynn
 
Last edited:
Using one of the forms key events is the easiest way I can think of. I was considering suggesting attaching key events to the UserControls child controls and trap them that way, but I'm not sure if this would work correctly or be worth the effort. Still I've put the idea out there so you can give it a go if you want.
 
Back
Top