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. MenuItem.Shortcut has no Esc key?!

MenuItem.Shortcut has no Esc key?!

Scheduled Pinned Locked Moved C#
questionlearning
6 Posts 4 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.
  • P Offline
    P Offline
    profoundwhispers
    wrote on last edited by
    #1

    Why is that? How else can I assign the Esc shortcut to a menu item? Sammy "A good friend, is like a good book: the inside is better than the cover..."

    N H 2 Replies Last reply
    0
    • P profoundwhispers

      Why is that? How else can I assign the Esc shortcut to a menu item? Sammy "A good friend, is like a good book: the inside is better than the cover..."

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      profoundwhispers wrote: How else can I assign the Esc shortcut to a menu item? You can P/Invoke RegisterHotKey, you might also want to include UnregisterHotKey. However why would you want to assign Esc to a menu item, usually when a form is open and someone presses the Esc key it will close the current window. - Nick Parker
        My Blog

      M 1 Reply Last reply
      0
      • P profoundwhispers

        Why is that? How else can I assign the Esc shortcut to a menu item? Sammy "A good friend, is like a good book: the inside is better than the cover..."

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        The old fashion way: set the MenuItem.Text to "My Caption\tEsc". Notice that you should inserting a tab character between the caption and the shortcut. Don't use the PropertyGrid to do this, since it will escape the backslash (\) as well. You'll need to handle the escape key yourself, though, by setting Form.KeyPreview to true and overriding the OnKeyDown method in your derived Form class to handle Keys.Escape.

        Microsoft MVP, Visual C# My Articles

        1 Reply Last reply
        0
        • N Nick Parker

          profoundwhispers wrote: How else can I assign the Esc shortcut to a menu item? You can P/Invoke RegisterHotKey, you might also want to include UnregisterHotKey. However why would you want to assign Esc to a menu item, usually when a form is open and someone presses the Esc key it will close the current window. - Nick Parker
            My Blog

          M Offline
          M Offline
          Mazdak
          wrote on last edited by
          #4

          Nick Parker wrote: However why would you want to assign Esc to a menu item Oh, I hate unstandard windows application like this, you can't do anything with them. :doh: Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

          P 1 Reply Last reply
          0
          • M Mazdak

            Nick Parker wrote: However why would you want to assign Esc to a menu item Oh, I hate unstandard windows application like this, you can't do anything with them. :doh: Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

            P Offline
            P Offline
            profoundwhispers
            wrote on last edited by
            #5

            Actually, what I'm trying to do is pretty standard, although it's a workaround. See, when I use the AxWebBrowser control, pressing on Esc to stop the page from loading doesn't seem to work, so I was trying to make it work! So how can I simply make it work!? Sammy "A good friend, is like a good book: the inside is better than the cover..."

            N 1 Reply Last reply
            0
            • P profoundwhispers

              Actually, what I'm trying to do is pretty standard, although it's a workaround. See, when I use the AxWebBrowser control, pressing on Esc to stop the page from loading doesn't seem to work, so I was trying to make it work! So how can I simply make it work!? Sammy "A good friend, is like a good book: the inside is better than the cover..."

              N Offline
              N Offline
              Nick Parker
              wrote on last edited by
              #6

              profoundwhispers wrote: Actually, what I'm trying to do is pretty standard, although it's a workaround. See, when I use the AxWebBrowser control, pressing on Esc to stop the page from loading doesn't seem to work, so I was trying to make it work! Well, I am not sure what a menu item has to do with what you just said, per your original post. I still think you are going to want to use the RegisterHotKey and probably override the WndProc. Something like the following:

              protected override void WndProc(ref Message m)
              {
              const int WM_HOTKEY = 0x0312;
              switch(m.Msg)
              {
              case WM_HOTKEY:
              ProcessHotKey();
              }
              base.WndProc(ref m);
              }

              private void ProcessHotKey()
              {
              // Handle AxWebBrowser here.
              }

              - Nick Parker
                My Blog

              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