Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. "Forwarding" key presses to parent form

"Forwarding" key presses to parent form

Scheduled Pinned Locked Moved C#
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Grunwald
    wrote on last edited by
    #1

    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.

    N 1 Reply Last reply
    0
    • D Daniel Grunwald

      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.

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • N Nader Elshehabi

        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

        D Offline
        D Offline
        Daniel Grunwald
        wrote on last edited by
        #3

        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.

        N 1 Reply Last reply
        0
        • D Daniel Grunwald

          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.

          N Offline
          N Offline
          Nader Elshehabi
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups