469,643 Members | 1,877 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

KeyDown Event not firing at all...?! Please help!

i'm working with visual studio 2005 and have a solution with 16
projects in it.

this specific application has a base form with other forms added to it
at any area of the application that the user navigates to through the
nav panel

anyways, on one of the forms i'm attempting to have a configuration
setting set to a hotkey press for the user to be able to reset a
feature with a hotkey combination

in design mode, i had the form that i want the event hooked to
selected, go to the events properties, double click the keydown event
then add this code:

private void form_KeyDown(object sender, KeyEventArgs e)
if (e.KeyData == (Keys.Shift | Keys.R))
MessageBox.Show("SHIFT + R");

obviously the hotkey combination is the shift key + the R key.
however, nothing happens when i debug this application and test the key
combination on this form.

i also set a breakpoint on the "if statement" to see if it hits and it
does not even hit the if statement in the keydown event

any and all help would be greatly appreciated, thank you.


Mar 29 '06 #1
4 13140
Set your form's KeyPreview property to true.

Mar 30 '06 #2
Set your form's KeyPreview property to true.

Mar 30 '06 #3
thank you, that makes sense, although the form i am working with has no
such property.
i think it has to do with the parent form that it's inheriting from.
i'll figure it out, you got me on the right track.

thank you very much for help.

Mar 30 '06 #4
i found the keypreview property of the parent form but even when i set
it to true, the events on the child form are not being raised...?

i'm at a loss. i set breakpoints on the keyevents that i set on the
child form and no matter what, they're not being hit.

here is my code:

in the formload:

//i set the parent's property to true on that actual form also, but
this is just to verify for good measure
this.ParentForm.KeyPreview = true;
this.KeyDown += new KeyEventHandler(ReportModule_KeyDown);

then in the ReportModule_KeyDown event:

void ReportModule_KeyDown(object sender, KeyEventArgs e)
if (e.Alt && e.KeyCode.ToString() == "F")
this.ParentForm.KeyPreview = false;
MessageBox.Show("reportmodule keydown");

and nothing. i set a breakpoint at the start of this event and it isn't
hitting that breakpoint at all when i do Alt+F. i also tried it for
keydown period, no if statement
and it also didn't get hit...?

Apr 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by CoderOfBugs | last post: by
3 posts views Thread by Peter S | last post: by
4 posts views Thread by Anne | last post: by
9 posts views Thread by runner7 | last post: by
3 posts views Thread by MLM450 | last post: by
5 posts views Thread by T | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.