devxlogo

Custom Menu Accelerators

Custom Menu Accelerators

To set the shortcut key of a menu item to something other than what the VB menu editor displays, use this code in the Form_Load event of a form:

 	Private Sub Form_Load()		mnuExit.Caption = mnuExit.Caption & vbTab & "ALT+F4"	End Sub

This adds the text “ALT+F4” to the caption of the mnuExit menu item and right-justifies it with any other shortcuts on the menu. ALT+F4 is already supported by Windows to close a window, so this shortcut needs no additional code for an exit menu choice. If you add shortcuts that Windows doesn’t internally support, then set the KeyPreview property of the form to True and check the KeyUp event on the form to see if the shortcut was selected.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist