locked
Assign a shortcut key to a button. RRS feed

  • Question

  • This seems like it should be easy, but I can't find anything on it. 

     

    How do I assign say "F12" to a button on a win form??

     

    Thanks,

     

    Dylan Etscorn

    Tuesday, November 13, 2007 4:09 PM

Answers

  • Hey, if you are trying to do this in a Windows Form, you can go to this site, it's very helpful. I tried it out myself and works fine.

     

    http://support.microsoft.com/kb/839201

     

    Make sure to add the this.KeyPreview probably after your InitializeComponant() function to true. Otherwise, the events won't fire.

     

    The code for F12 is 123 I believe.

     

    Cheers,

     

    Tuesday, November 13, 2007 4:22 PM
  • "Buttons normally have accelerator keys (EG Alt+G) rather than shortcut keys (EG Ctrl+G). Accelerator keys are set using the Text property of the button. Put an ampersand (&) before the letter in the caption you want the button to react to.

    When the user presses Alt, all the accelerators on the form get underlined."

    you can either process the form keyboard message to invoke the button click event when F12 is pressed, or maybe you could use an menu item that has the short cut key to associate it.


    Tuesday, November 13, 2007 4:24 PM

All replies

  • Hey, if you are trying to do this in a Windows Form, you can go to this site, it's very helpful. I tried it out myself and works fine.

     

    http://support.microsoft.com/kb/839201

     

    Make sure to add the this.KeyPreview probably after your InitializeComponant() function to true. Otherwise, the events won't fire.

     

    The code for F12 is 123 I believe.

     

    Cheers,

     

    Tuesday, November 13, 2007 4:22 PM
  • "Buttons normally have accelerator keys (EG Alt+G) rather than shortcut keys (EG Ctrl+G). Accelerator keys are set using the Text property of the button. Put an ampersand (&) before the letter in the caption you want the button to react to.

    When the user presses Alt, all the accelerators on the form get underlined."

    you can either process the form keyboard message to invoke the button click event when F12 is pressed, or maybe you could use an menu item that has the short cut key to associate it.


    Tuesday, November 13, 2007 4:24 PM