MenuItem.Visible 属性

定义

获取或设置一个值,通过该值指示菜单项是否可见。Gets or sets a value indicating whether the menu item is visible.

public:
 property bool Visible { bool get(); void set(bool value); };
public bool Visible { get; set; }
member this.Visible : bool with get, set
Public Property Visible As Boolean

属性值

如果菜单项在菜单上为可见,则为 true;否则为 falsetrue if the menu item will be made visible on the menu; otherwise, false. 默认值为 trueThe default is true.

示例

下面的代码示例创建一个菜单项,设置标题,分配快捷键,使菜单项可见,并显示菜单项的快捷键显示方式。The following code example creates a menu item, sets the caption, assigns a shortcut key, makes the menu item visible, and shows the shortcut key display for the menu item. 该示例要求创建了名为 menuItem1MenuItemThe example requires that a MenuItem has been created that is named menuItem1.

public:
   void SetupMyMenuItem()
   {
      // Set the caption for the menu item.
      menuItem1->Text = "&New";
      // Assign a shortcut key.
      menuItem1->Shortcut = Shortcut::CtrlN;
      // Make the menu item visible.
      menuItem1->Visible = true;
      // Display the shortcut key combination.
      menuItem1->ShowShortcut = true;
   }
public void SetupMyMenuItem()
{
   // Set the caption for the menu item.
   menuItem1.Text = "&New";
   // Assign a shortcut key.
   menuItem1.Shortcut = Shortcut.CtrlN;
   // Make the menu item visible.
   menuItem1.Visible = true;
   // Display the shortcut key combination.
   menuItem1.ShowShortcut = true;
}
  
Public Sub SetupMyMenuItem()
    ' Set the caption for the menu item.
    menuItem1.Text = "&New"
    ' Assign a shortcut key.
    menuItem1.Shortcut = Shortcut.CtrlN
    ' Make the menu item visible.
    menuItem1.Visible = True
    ' Display the shortcut key combination.
    menuItem1.ShowShortcut = True
End Sub

注解

您可以使用此属性修改菜单结构,而无需合并菜单或禁用菜单。You can use this property to modify a menu structure without having to merge menus or disable menus. 例如,如果你想要从应用程序的菜单中隐藏一整段功能,则可以通过将此属性设置为 false,将其从用户隐藏。For example, if you want to hide a complete section of functionality from the menus for your application, you can hide them from the user by setting this property to false.

适用于