Microsoft KB Archive/291007

= INFO: All Submenu Items Cannot Be Invisible =

Article ID: 291007

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition

-



This article was previously published under Q291007



SUMMARY
All submenu items in a menu cannot be set to invisible at run time or design time. At least one of the submenu items must remain visible at all times.



MORE INFORMATION
Visual Basic does not allow a top-level menu item with no submenu items to display. Therefore, setting all submenu items to invisible rasies an error message. If you attempt to deselect (uncheck) the Visible option for all submenus in the Menu Editor, and then click OK to save the menu, you receive the following error message:

At least one submenu item must be visible.

Steps to Demonstrate Run-Time Behavior
 Start a new Standard EXE project in Visual Basic. Form1 is created by default. On the Tools menu, click to select the Menu Editor. Create a menu on Form1 with a top-level menu with the caption Top and name mnuTop. Create two submenu items with captions Sub1 and Sub2, and names mnuSub1 and mnuSub2. Note that you create submenu items by pressing the RIGHT-ARROW button to indent one level.  Paste the following code into the General Declarations section of Form1: Option Explicit

Private Sub Form_Load mnuSub1.Visible = False mnuSub2.Visible = False End Sub  Press the F5 key to run the project, and note that you see the following error message:

Runtime Error '387':

'Visible' property can't be set on this control.

  Click End to dismiss the error, and then comment out the line: mnuSub2.Visible = False   Press F5, and note that there is no error. Note that making the top-level menu item invisible is fine. For example: mnuTop.Visible = False Naturally, with the top-level menu item invisible, this effectively removes all the submenu items as well. However, if you make the top-level item invisible, it can still be displayed as a shortcut menu. Any submenu items made invisible do not appear on the shortcut menu. </li></ol>

Keywords: kbinfo kbmenu kbcodesnippet KB291007

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.