How to Right Justify Top-Level Menus in Visual Basic

Last reviewed: February 18, 1996
Article ID: Q86772
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

SUMMARY

It is possible to right justify top-level menu items by including a CHR$(8) (backspace) as the first character of the caption for the left-most menu that you want to appear on the right side of the menu bar.

This article does not apply to Windows 95.

MORE INFORMATION

Microsoft publishes a book called "The Windows Interface: An Application Design Guide," which contains standards and guidelines for Windows 3.1. The following guidelines for right-justified Help menu items is taken from that book:

   "Some applications currently place the Help menu at the extreme right of
   the menu bar. The current recommendation is that the Help menu
   immediately follow the next-to-last menu item, for three reasons: (1) to
   increase the accessibility of the help menu; (2) to decrease the
   likelihood of pressing the Maximize or Minimize buttons by mistake when
   trying to access Help; and (3) to make the space at the extreme right of
   the menu bar available in MDI applications for a Restore icon for
   maximized child windows."

   Source: "The Windows Interface: An Application Design Guide"
   by Microsoft Corporation
   248 pages, plus two 3.5-inch disks
   ISBN: 1-55615-439-9
   Publication Date: October 9, 1992

Step-by-Step Example

  1. Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.

  2. From the Window menu, choose Menu Design Window.

  3. Create a menu item with One as both caption and control name.

  4. Choose the Next button, and repeat step 3 with using Two as the name.

  5. Choose Done to exit the Menu Design Window. You now have two top-level menus.

  6. Add the following code to the Form1 Form_Load event procedure:

       Sub Form_Load ()
          Two.Caption = Chr$(8) + Two.Caption
       End Sub
    
    

  7. Press the F5 key to run the program.

The Two menu item appears on the right side of the menu bar. If you add the backspace to the One menu caption, both menus will be right-justified.

Special Trick for Design Time

The technique given above can be done only at run time. However, here's a trick you can use to do the same thing at design time:

  1. Make a text file with ASCII character 8 in it.

  2. Load the text file into NOTEPAD.EXE and copy the character to the clipboard.

  3. Then, when you're in the Menu Design window, Press SHIFT-INS (Paste) in the caption field to place CHR$(8) character in it.


Additional reference words: 1.00 2.00 3.00 alignment right-aligned align
KBCategory: kbprg kbcode
KBSubcategory: PrgCtrlsStd


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.

Last reviewed: February 18, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.