DOCUMENT:Q161256 17-MAR-1997 [vbwin] TITLE :HOWTO: Customize Visual Basic Menus to Use Mnemonics PRODUCT :Microsoft Visual Basic for Windows PROD/VER:5.00 OPER/SYS:WINDOWS KEYWORDS:kbtool kbusage vb5all vb5howto VBKBEnv kbhowto ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Professional and Enterprise Editions, for Windows, version 5.0 --------------------------------------------------------------------- SUMMARY ======= Visual Basic menus are organized to minimize the number of keystrokes it takes to get to the most frequently-used options. Still, some options require several extra keystrokes you may want to eliminate if you use the option regularly. This article describes how to customize the Visual Basic for Windows menu to create a new, top-level menu item with mnemonic key access. MORE INFORMATION ================ Some menu operations in Visual Basic for Windows require multiple keystrokes or mouse actions. The best example of this is the Bookmark option. To toggle a bookmark in a code window with the keyboard, the keystrokes are: ALT+E+B+T To accomplish this behavior with the mouse, you must do three clicks and open two menus. There are no designated accelerator keys for these operations. This can be changed to a single mnemonic ALT+ with the customizable menus introduced in Visual Basic for Windows version 5.0. The following example assigns an ALT+B mnemonic to the menu option: Edit Bookmark Toggle. Step-by-Step Example -------------------- 1. Start a new Standard EXE project. Form1 is added by default. 2. Copy and paste the following code to the Form1 Code Window: Private Sub Form_Load() MsgBox "Toggle here" End Sub 3. Right-click the Menu Bar, and choose View, Toolbars, Customize from the menus. The customize window appears. 4. Select the Commands Tab. 5. Choose the "Edit" category and drag the command picture for Toggle Bookmark to your menu bar. NOTE: Do not close the Customize Window at this point: leaving it open determines what menu will be displayed for a right-click. If it is closed, you get the standard menu. 6. When you right-click the newly-dropped command picture, you will see a special options menu that includes changing the mnemonic and displaying text. 7. Change the Name property from "&Toggle Bookmark" to "Toggle &Bookmark." This is to avoid conflict with the existing "&Tools" menu. Alternatively, you could remove the "&" mnemonic from the Tools menu to allow ALT+T to toggle bookmarks. 8. Choose "Text Only (Always)" to display only text in the menu bar or choose "Image and Text" to display both the command picture and the text. Note that you must display the text for the mnemonic to be enabled. 9. Close the customize window. 10. Press the F5 key to run the project, or click "Run Project" from the Tools menu. 11. Position the edit cursor (caret) in the Form1 code window on the line: MsgBox "Toggle here" and press ALT+T. The symbol indicating a bookmark should appear in the left margin of the code window. REFERENCES ========== Customize Command (Shortcut Menu), Customize Dialog Box (c) Microsoft Corporation 1996, All Rights Reserved. Contributions by Ted Keith, Microsoft Corporation ====================================================================== Keywords : kbtool kbusage vb5all vb5howto VBKBEnv kbhowto Version : 5.00 Platform : WINDOWS Issue type : kbhowto ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1997.