Tech Off Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Shortcut keys to buttons in C# program

Back to Forum: Tech Off
  • User profile image


    I know it's possible to have shortcut keys to menu items in a C# program (Like CTRL+F5).
    Is it possible to have shortcut keys for Buttons, or do I need to have a menu just to get the shortcut keys?

  • User profile image

    You could set the KeyPreview property of your Form to true, and then subscribe to the KeyDown event.
    There, you simply put an if statement .. if (e.keycode == keys.return) ...


  • User profile image

    Thanks alot, I'll try that Smiley

  • User profile image

    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.

    Note that the form's Accept button automatically reacts to the Enter key and it's cancel button reacts to the Escape key. Both of these are properties of the form.

    You should not put Accelerators on the Accept or Cancel button.

    IE Button captions should not be OK or Cancel because you don't need to be able to press Alt+O as well as Return to do the same thing.


  • User profile image

    Thanks a lot. It works.

  • User profile image
    Deactivated User

    Comment removed at user's request.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.