Redirect or capture keydown event from a child form

F

Frank T. Clark

How do I redirect or capture keydown events in a parent form from a child
form?

I have a main form which displays another informational form marked
"SizableToolWindow".

Form child = new ChildForm();

this.AddOwnedForm (child);

child.Show();

I don't want the child form to be active just to show information. I do want
the user to be able to move the form and change the size. How do I make sure
that the information from any keydown events goes to the parent form?

I have programmed extensively in C using the Win32 API but I am only
starting with C#.
 
W

Wasu

You could create an event in the child. The parent
subscribes to it.
Whenever the keydown is fired on the child, you should
fire your event. Since the main form will be subcribing to
it, it will also get the events.

-Wasu
 
T

Tim Matteson

Try adding a KeyEventHandler when you create the child form:

//Create child
private void mnuFileNew_Click(object sender, System.EventArgs e)
{
frmChild child = new frmChild();
frmChild.MdiParent = this;
frmChild.Show();
//Raise keydown events to this form
frmChild.KeyDown +=new KeyEventHandler(frmChild_KeyDown);
}
//Child form KeyDown event raised to parent
private void frmChild_KeyDown(object sender, KeyEventArgs e)
{
//process key here
}
 
F

Frank T. Clark

Thank you. I always say. "The answer is simple... Once you know the answer."
:)
 

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