MenuItem.Visible 属性
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,通过该值指示菜单项是否可见。
public:
property bool Visible { bool get(); void set(bool value); };
C#
public bool Visible { get; set; }
member this.Visible : bool with get, set
Public Property Visible As Boolean
如果菜单项在菜单上为可见,则为 true
;否则为 false
。 默认值为 true
。
下面的代码示例创建一个菜单项,设置标题,分配快捷键,使菜单项可见,并显示菜单项的快捷键显示。 该示例要求 MenuItem 已创建一 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;
}
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;
}
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
可以使用此属性来修改菜单结构,而无需合并菜单或禁用菜单。 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 |