Send Keyboard messages from one window to another?

  • Thread starter Hong Kong Phooey
  • Start date
H

Hong Kong Phooey

I have an app with two windows, neither is shown modally. One is a main
window, one is a tool window. My main window has several menus on it. What I
want is when someone uses the keyboard on the tool window, for the message
to get sent to the main window.

If someone types Ctrl+O on the tool window, I want the main window to
process it and show its Open Dialog, etc. I have a reference to the main
window inside the tool window and vice versa.

Can anyone lend some insight?

--

Any help is appreciated.
Thanks in advance.

Hong Kong Phooey
 
G

Gabriel Lozano-Morán

I am not saying that this is the best solution but it might be a solution
for your problem. Add the following code to your MdiParent:

Assumptions made:
1) You use a MdiContainer
2) Main window variable is childForm1

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
{
case Keys.Alt | Keys.O:
{
childForm1.Activate();
return false;
}
}

return base.ProcessCmdKey(ref msg, keyData);
}

Gabriel Lozano-Morán
 

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