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. Link Keyboard Shortcut to Button

Link Keyboard Shortcut to Button

Scheduled Pinned Locked Moved C#
questiontutorial
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
    polishprogrammer
    wrote on last edited by
    #1

    How do I link a keyboard shortcut to a button on a form? I have added shortcuts to menu items-that is very straightforward-but for some reason, I cannot find information on how to add the shortcut to a button. Thanks.

    A D N 3 Replies Last reply
    0
    • P polishprogrammer

      How do I link a keyboard shortcut to a button on a form? I have added shortcuts to menu items-that is very straightforward-but for some reason, I cannot find information on how to add the shortcut to a button. Thanks.

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      just use Amperion ("&") before the charecter on which you want to use Keyboard Shortcut. e.g : Button Text="Click" Just Give "&Click" and on Runtime -> "Alt + C" will invoked Button Click Methods !!!!

      cheers, Abhijit Check My Latest Article

      D P 2 Replies Last reply
      0
      • A Abhijit Jana

        just use Amperion ("&") before the charecter on which you want to use Keyboard Shortcut. e.g : Button Text="Click" Just Give "&Click" and on Runtime -> "Alt + C" will invoked Button Click Methods !!!!

        cheers, Abhijit Check My Latest Article

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        Amperion :confused: Ampersand[^]

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Expect everything to be hard and then enjoy the things that come easy. (code-frog)

        1 Reply Last reply
        0
        • P polishprogrammer

          How do I link a keyboard shortcut to a button on a form? I have added shortcuts to menu items-that is very straightforward-but for some reason, I cannot find information on how to add the shortcut to a button. Thanks.

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          Abhijit's answer is correct. if you want to assign function keys, you'll have to set the Form's KeyPreview property to true and handle the Form's KeyPress or KeyDown events and call the PerformClick method (and Focus if you need it) of the button you want pressed.

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Expect everything to be hard and then enjoy the things that come easy. (code-frog)

          1 Reply Last reply
          0
          • A Abhijit Jana

            just use Amperion ("&") before the charecter on which you want to use Keyboard Shortcut. e.g : Button Text="Click" Just Give "&Click" and on Runtime -> "Alt + C" will invoked Button Click Methods !!!!

            cheers, Abhijit Check My Latest Article

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

            Is there a symbol that can be used for Ctrl + C instead of Alt + C? Thansk.

            1 Reply Last reply
            0
            • P polishprogrammer

              How do I link a keyboard shortcut to a button on a form? I have added shortcuts to menu items-that is very straightforward-but for some reason, I cannot find information on how to add the shortcut to a button. Thanks.

              N Offline
              N Offline
              Nirandas
              wrote on last edited by
              #6

              You may want to take a look at this blog post. http://nirandas.com/blog/index.php/ways-to-set-short-cut-keys-for-controls-on-a-windows-forms-net-application/[^] HTH

              Nirandas, a developer from India. http://www.nirandas.com

              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