KeyDown inconsistency

T

Tim Johnson

I put a form_KeyDown event handler in my form, looking for the hardware
navigation key presses (up,down) so the user can scroll a listbox. Works
great. But the form loading was a little slow, so in the form that loads
this form, I "preload" it by doing a form2 f = new form2() ahead of time,
during form1's load event; then later I do the f.ShowDialog to bring up
form2.

But in this preload scenario, suddenly I'm not getting the hardware keydown
events any more. I added the event handler initially in the form2
InitializeComponent method with all the others, then moved it to the load
event thinking that might help (since it's called only at the ShowDialog
time). Still no good. Odder still, if I go to form3 from form2, then come
back again, suddenly on form2 my hw nav keys are now being caught.

Note it's not a matter of the listbox having focus, since it's the KeyDown
form event, not an subclassed override to the KeyDown control event.

How come preloading the form somehow misses the KeyDown event handler? Is
there a better place to add this event handler than the constructor or load
handler?

--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 
B

Bruce Hamilton [MSFT]

Have you set Form.KeyPreview = True in the constructor for your form?

- Bruce Hamilton
.NET Compact Framework User Education
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top