"Forwarding" key presses to parent form
-
My main form can open multiple non-modal child windows (FormBorderStyle.FixedToolWindow, Owner set to the main form). The main form has a MainMenuStrip with items that have shortcuts (e.g. Ctrl+F for "find", Ctrl+R for "replace"). But inside the "find" dialog, pressing Ctrl+R has no effect (well, it plays a beeping sound...). How can I send the key presses to the MainMenuStrip? I want to forward only those key presses that are not handled by the child window.
-
My main form can open multiple non-modal child windows (FormBorderStyle.FixedToolWindow, Owner set to the main form). The main form has a MainMenuStrip with items that have shortcuts (e.g. Ctrl+F for "find", Ctrl+R for "replace"). But inside the "find" dialog, pressing Ctrl+R has no effect (well, it plays a beeping sound...). How can I send the key presses to the MainMenuStrip? I want to forward only those key presses that are not handled by the child window.
Hello I think this would be a simple task -Even though I don't think I like the idea- Simply -I suppose- you have your KeyUp event handlers in your child forms. When they catch a key that should be passed to the parent they should call a public method to your main From. eg. ChildFormKeyDownHandler(EventArgs e) { //Handle my keys //... //... if(e.Key == somekey) { myParent.PublicMethod(); } } While sending the keys themselves to the parent form won't gain you anything. Yet if you still insist on this try looking for "SendKeys" class in your MSDN
-
Hello I think this would be a simple task -Even though I don't think I like the idea- Simply -I suppose- you have your KeyUp event handlers in your child forms. When they catch a key that should be passed to the parent they should call a public method to your main From. eg. ChildFormKeyDownHandler(EventArgs e) { //Handle my keys //... //... if(e.Key == somekey) { myParent.PublicMethod(); } } While sending the keys themselves to the parent form won't gain you anything. Yet if you still insist on this try looking for "SendKeys" class in your MSDN
I cannot use SendKeys because I don't want to change focus to the main window. And thanks, I know how to call public methods on other forms, but I did not find a way to call shortcuts in a MainMenuStrip. I don't want to write the code searching the correct item for the shortcut myself because the main menu can be extended by AddIns in different ways.
-
I cannot use SendKeys because I don't want to change focus to the main window. And thanks, I know how to call public methods on other forms, but I did not find a way to call shortcuts in a MainMenuStrip. I don't want to write the code searching the correct item for the shortcut myself because the main menu can be extended by AddIns in different ways.
Hello again I didn't mean to offend you in any way, yet just like I said, what is the point of calling a shortcut of a form that's not active!! Anyway I'm just trying to help here.:) Three hints: 1- You can activate the parent form, do the SendKeys, then reactivate the last active child form 2- You can import an old API function named "SendMessage" or "PostMessage", tyhen use your parent's Handle to send a WM_KeyDown message. 3- You can make the parent's event handlers call public methods, and call them from the child froms Or you can just check this link, it might help http://www.codeproject.com/cpp/sendkeys_cpp_Article.asp[^] Sorry it's C++;) That was all I could come up with. I hope it would be of some use.