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.

devx-admin

Share the Post: