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

V

velasquez.m

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
 
G

ghost

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.
 
G

ghost

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...?
 

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