By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,202 Members | 1,477 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,202 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

mike

Mar 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Set your form's KeyPreview property to true.

Mar 30 '06 #2

P: n/a
Set your form's KeyPreview property to true.

Mar 30 '06 #3

P: n/a
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

P: n/a
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.