MenuItem.Visible 属性

定义

获取或设置一个值,通过该值指示菜单项是否可见。

C#
public bool Visible { get; set; }

属性值

Boolean

如果菜单项在菜单上为可见,则为 true;否则为 false。 默认值为 true

示例

下面的代码示例创建一个菜单项,设置标题,分配快捷键,使菜单项可见,并显示菜单项的快捷键显示。 该示例要求 MenuItem 已创建一 menuItem1个名为 ..

C#
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;
}

注解

可以使用此属性来修改菜单结构,而无需合并菜单或禁用菜单。 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.

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0