Menu 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
Menu is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use ToolStripDropDown and ToolStripDropDownMenu instead.
表示所有菜单的基本功能。
此类在 .NET Core 3.1 及更高版本中不可用。 请 ToolStripDropDown 改用和 ToolStripDropDownMenu 扩展 Menu 控件。
public ref class Menu abstract : System::ComponentModel::Component
[System.ComponentModel.ListBindable(false)]
public abstract class Menu : System.ComponentModel.Component
[System.ComponentModel.ListBindable(false)]
[System.ComponentModel.Browsable(false)]
[System.Obsolete("`Menu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ToolStripDropDown` and `ToolStripDropDownMenu` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
public abstract class Menu : System.ComponentModel.Component
[<System.ComponentModel.ListBindable(false)>]
type Menu = class
inherit Component
[<System.ComponentModel.ListBindable(false)>]
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("`Menu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ToolStripDropDown` and `ToolStripDropDownMenu` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
type Menu = class
inherit Component
Public MustInherit Class Menu
Inherits Component
- 继承
- 派生
- 属性
示例
下面的代码示例使用派生类 MenuItem为窗体创建菜单结构。 示例代码添加一个 MenuItem 表示顶级菜单项,向它添加一个子菜单项以选择字号,然后将两个子菜单项添加到代表应用程序中的大字体和小字体选项的菜单项。 该示例要求有一mainMenu1个名为的对象和四MenuItemmenuItem1个名为 MainMenu 、menuItem2、 menuItem3和menuItem4的对象。
public:
void CreateMyMenu()
{
// Set the caption for the top-level menu item.
menuItem1->Text = "Edit";
// Set the caption for the first submenu.
menuItem2->Text = "Font Size";
// Set the caption for menuItem2's first submenu.
menuItem3->Text = "Small";
// Set the checked property to true since this is the default value.
menuItem3->Checked = true;
// Define a shortcut key combination for the menu item.
menuItem3->Shortcut = Shortcut::CtrlS;
// Set the caption of the second sub menu item of menuItem2.
menuItem4->Text = "Large";
// Define a shortcut key combination for the menu item.
menuItem4->Shortcut = Shortcut::CtrlL;
// Set the index of the menu item so it is placed below the first submenu item.
menuItem4->Index = 1;
// Add menuItem3 and menuItem4 to menuItem2's list of menu items.
menuItem2->MenuItems->Add( menuItem3 );
menuItem2->MenuItems->Add( menuItem4 );
// Add menuItem2 to menuItem1's list of menu items.
menuItem1->MenuItems->Add( menuItem2 );
// Add menuItem1 to the MainMenu for displaying.
mainMenu1->MenuItems->Add( menuItem1 );
}
public void CreateMyMenu()
{
// Set the caption for the top-level menu item.
menuItem1.Text = "Edit";
// Set the caption for the first submenu.
menuItem2.Text = "Font Size";
// Set the caption for menuItem2's first submenu.
menuItem3.Text = "Small";
// Set the checked property to true since this is the default value.
menuItem3.Checked = true;
// Define a shortcut key combination for the menu item.
menuItem3.Shortcut = Shortcut.CtrlS;
// Set the caption of the second sub menu item of menuItem2.
menuItem4.Text = "Large";
// Define a shortcut key combination for the menu item.
menuItem4.Shortcut = Shortcut.CtrlL;
// Set the index of the menu item so it is placed below the first submenu item.
menuItem4.Index = 1;
// Add menuItem3 and menuItem4 to menuItem2's list of menu items.
menuItem2.MenuItems.Add(menuItem3);
menuItem2.MenuItems.Add(menuItem4);
// Add menuItem2 to menuItem1's list of menu items.
menuItem1.MenuItems.Add(menuItem2);
// Add menuItem1 to the MainMenu for displaying.
mainMenu1.MenuItems.Add(menuItem1);
}
Public Sub CreateMyMenu()
' Set the caption for the top-level menu item.
menuItem1.Text = "Edit"
' Set the caption for the first submenu.
menuItem2.Text = "Font Size"
' Set the caption for menuItem2's first submenu.
menuItem3.Text = "Small"
' Set the checked property to true since this is the default value.
menuItem3.Checked = True
' Define a shortcut key combination for the menu item.
menuItem3.Shortcut = Shortcut.CtrlS
' Set the caption of the second sub menu item of menuItem2.
menuItem4.Text = "Large"
' Define a shortcut key combination for the menu item.
menuItem4.Shortcut = Shortcut.CtrlL
' Set the index of the menu item so it is placed below the first submenu item.
menuItem4.Index = 1
' Add menuItem3 and menuItem4 to menuItem2's list of menu items.
menuItem2.MenuItems.Add(menuItem3)
menuItem2.MenuItems.Add(menuItem4)
' Add menuItem2 to menuItem1's list of menu items.
menuItem1.MenuItems.Add(menuItem2)
' Add menuItem1 to the MainMenu for displaying.
mainMenu1.MenuItems.Add(menuItem1)
End Sub
注解
此类在 .NET Core 3.1 及更高版本中不可用。 请改用 ToolStripDropDown 和 ToolStripDropDownMenu。
此类是 MainMenu、MenuItem 和 ContextMenu 类的基类。 不能创建此类的实例。 应用程序的菜单由对象组成 MenuItem 。 这些对象可以包含其他 MenuItem 对象,表示子菜单项。 MenuItem对象可以存储在窗体或用于显示快捷菜单的整个ContextMenu菜单结构中MainMenu。 此类提供所有菜单类通用的功能。
与许多基类不同,该 Menu 类使用其派生类来定义其许多属性。 如果在多文档界面(MDI)应用程序中使用菜单,则可以使用该 MdiListItem 属性指定一个 MenuItem 在应用程序中显示打开的 MDI 子窗体的列表。 该 MenuItems 属性包含存储在菜单类中的对象列表 MenuItem 。 对于或MainMenuContextMenu,此属性包含显示的所有MenuItem对象。 对于 a MenuItem,该 MenuItems 属性表示与其关联的子菜单项。
除了为所有派生菜单类提供的属性外,该 Menu 类还提供方法,例如 CloneMenu ,以及 MergeMenu,使你能够从现有菜单中创建新菜单,以及同时合并两个菜单结构。
该 Menu 类还定义嵌套类 Menu.MenuItemCollection。 此类定义属性使用MenuItems的对象集合MenuItem。 可以使用类的方法
构造函数
| 名称 | 说明 |
|---|---|
| Menu(MenuItem[]) |
已过时.
初始化 Menu 类的新实例。 |
字段
| 名称 | 说明 |
|---|---|
| FindHandle |
已过时.
指定 FindMenuItem(Int32, IntPtr) 该方法应搜索句柄。 |
| FindShortcut |
已过时.
指定 FindMenuItem(Int32, IntPtr) 该方法应搜索快捷方式。 |
属性
| 名称 | 说明 |
|---|---|
| CanRaiseEvents |
已过时.
获取一个值,该值指示组件是否可以引发事件。 (继承自 Component) |
| Container |
已过时.
IContainer获取包含 .Component (继承自 Component) |
| DesignMode |
已过时.
获取一个值,该值指示当前是否 Component 处于设计模式。 (继承自 Component) |
| Events |
已过时.
获取附加到此 Component对象的事件处理程序的列表。 (继承自 Component) |
| Handle |
已过时.
获取一个值,该值表示菜单的窗口句柄。 |
| IsParent |
已过时.
获取一个值,该值指示此菜单是否包含任何菜单项。 此属性为只读。 |
| MdiListItem |
已过时.
获取一个值,该值指示 MenuItem 用于显示多个文档界面 (MDI) 子窗体的列表。 |
| MenuItems |
已过时.
获取一个值,该值指示与菜单关联的对象的集合 MenuItem 。 |
| Name |
已过时.
获取或设置 . 的名称 Menu。 |
| Site |
已过时.
(继承自 Component)
|
| Tag |
已过时.
获取或设置与控件关联的用户定义的数据。 |
方法
活动
| 名称 | 说明 |
|---|---|
| Disposed |
已过时.
当组件通过对方法的调用 Dispose() 释放时发生。 (继承自 Component) |