Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combobox & form keypress event

Status
Not open for further replies.

Durkin

Programmer
Nov 6, 2000
304
GB
Hi. I have the keypreview property of a form set to True and I am handling certain keys at the form level. This works fine for all controls except when a combobox has the focus. Has anyone seen this before and is there a remedy?

Durkin
 
Yes, I have had it before.

I just have a keypress event for the combobox which directs it to the function to run whatever code you need to run.

Are you trying to catch the escape key to close a form or something similar??
 
Yes something like that. I have an application using mdi forms. I have certain 'hotkeys' that do things like close the current form, switch forms etc. I want the mdi parent form to catch these and deal with them without going to the child form at all. So, I don't want to have to code for every combobox in the app cause there are quite a few and it would be easy to miss one or two.

Durkin
 
If you don't want the combobox to maintain focus after it is used, you can add a line of code to give the focus to another control after the combobox processing is done. There may be other solutions, but This is all I could think of right now. If I find more info, I will get back to you.

Becca
 
Sorted. I was using a derived combobox so I stuck in an overridden OnKeyDown method. It calls a routine on the parent form which accepts the KeyEventArgs from the control. So if it handles the keydown event the control does nothing and if it doesn't then the combobox does it's normal thing.
Thanks for your help.

Durkin
 
Sounds cool, I am still learning .net myself so some things are beyond me, but I am always glad to help where I can.

Becca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top