MainMenu MainMenu MainMenu MainMenu Class

定义

表示窗体的菜单结构。Represents the menu structure of a form. 尽管 MenuStrip 替换了早期版本的 MainMenu 控件并添加了功能;但是也可选择保留 MainMenu 以备向后兼容和将来使用。Although MenuStrip replaces and adds functionality to the MainMenu control of previous versions, MainMenu is retained for both backward compatibility and future use if you choose.

public ref class MainMenu : System::Windows::Forms::Menu
public class MainMenu : System.Windows.Forms.Menu
type MainMenu = class
    inherit Menu
Public Class MainMenu
Inherits Menu
继承

示例

下面的代码示例将创建MainMenu,将分配两个MenuItem对象添加到MainMenu并将其绑定到窗体。The following code example creates a MainMenu, assigns two MenuItem objects to the MainMenu and binds it to a form. 此示例要求具有Form创建名为Form1This example requires that you have a Form created that is named Form1.

void CreateMyMainMenu()
{
   // Create an empty MainMenu.
   MainMenu^ mainMenu1 = gcnew MainMenu;
   MenuItem^ menuItem1 = gcnew MenuItem;
   MenuItem^ menuItem2 = gcnew MenuItem;
   menuItem1->Text = "File";
   menuItem2->Text = "Edit";

   // Add two MenuItem objects to the MainMenu.
   mainMenu1->MenuItems->Add( menuItem1 );
   mainMenu1->MenuItems->Add( menuItem2 );

   // Bind the MainMenu to Form1.
   Menu = mainMenu1;
}
public void CreateMyMainMenu()
{
   // Create an empty MainMenu.
   MainMenu mainMenu1 = new MainMenu();

   MenuItem menuItem1 = new MenuItem();
   MenuItem menuItem2 = new MenuItem();

   menuItem1.Text = "File";
   menuItem2.Text = "Edit";
   // Add two MenuItem objects to the MainMenu.
   mainMenu1.MenuItems.Add(menuItem1);
   mainMenu1.MenuItems.Add(menuItem2);
   
   // Bind the MainMenu to Form1.
   Menu = mainMenu1;   
}

Public Sub CreateMyMainMenu()
    ' Create an empty MainMenu.
    Dim mainMenu1 As New MainMenu()
       
    Dim menuItem1 As New MenuItem()
    Dim menuItem2 As New MenuItem()
       
    menuItem1.Text = "File"
    menuItem2.Text = "Edit"
    ' Add two MenuItem objects to the MainMenu.
    mainMenu1.MenuItems.Add(menuItem1)
    mainMenu1.MenuItems.Add(menuItem2)
       
    ' Bind the MainMenu to Form1.
    Menu = mainMenu1
End Sub

注解

MainMenu控件表示窗体菜单结构的容器。The MainMenu control represents the container for the menu structure of a form. 组成一个菜单MenuItem代表菜单结构中的各个菜单命令的对象。A menu is composed of MenuItem objects that represent the individual menu commands in the menu structure. 每个MenuItem可以是你的应用程序的命令或其他子菜单项将父菜单。Each MenuItem can be a command for your application or a parent menu for other submenu items. 若要将绑定MainMenuForm,将显示它,将分配MainMenuMenu属性FormTo bind the MainMenu to the Form that will display it, assign the MainMenu to the Menu property of the Form.

对于必须支持多种语言的应用程序,可以使用RightToLeft属性来显示菜单从右到左,以支持阿拉伯语等语言的文本。For applications that will have support for multiple languages, you can use the RightToLeft property to display the text of the menu from right to left to support languages such as Arabic.

您可以创建不同MainMenu对象来表示不同的菜单结构的窗体。You can create different MainMenu objects to represent different menu structures for your form. 如果你想要重复使用包含在特定的菜单结构MainMenu,可以使用其CloneMenu方法来创建副本。If you want to reuse the menu structure contained in a specific MainMenu, you can use its CloneMenu method to create a copy. 菜单结构的副本后,你可以为新菜单结构进行适当的修改。Once you have a copy of the menu structure, you can make the appropriate modifications for your new menu structure.

备注

剪切和粘贴的菜单项从一个窗体设计器中的另一个可能无法按预期将粘贴到窗体是否定义没有任何菜单项。Cutting and pasting menu items from one form to another in the designer might not work as expected if the form you are pasting into has no menu items defined.

构造函数

MainMenu() MainMenu() MainMenu() MainMenu()

初始化没有任何指定菜单项的 MainMenu 类的一个新实例。Initializes a new instance of the MainMenu class without any specified menu items.

MainMenu(IContainer) MainMenu(IContainer) MainMenu(IContainer) MainMenu(IContainer)

使用指定的容器初始化 MainMenu 类的新实例。Initializes a new instance of the MainMenu class with the specified container.

MainMenu(MenuItem[]) MainMenu(MenuItem[]) MainMenu(MenuItem[]) MainMenu(MenuItem[])

使用一组指定的 MainMenu 对象初始化 MenuItem 的一个新实例。Initializes a new instance of the MainMenu with a specified set of MenuItem objects.

属性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Handle Handle Handle Handle

获取表示菜单的窗口句柄的值。Gets a value representing the window handle for the menu.

(Inherited from Menu)
IsParent IsParent IsParent IsParent

获取一个值,通过该值指示此菜单是否包含任何菜单项。Gets a value indicating whether this menu contains any menu items. 此属性是只读的。This property is read-only.

(Inherited from Menu)
MdiListItem MdiListItem MdiListItem MdiListItem

获取一个值,通过该值指示用于显示多文档界面 (MDI) 子窗体列表的 MenuItemGets a value indicating the MenuItem that is used to display a list of multiple document interface (MDI) child forms.

(Inherited from Menu)
MenuItems MenuItems MenuItems MenuItems

获取一个值,通过该值指示与菜单关联的 MenuItem 对象的集合。Gets a value indicating the collection of MenuItem objects associated with the menu.

(Inherited from Menu)
Name Name Name Name

获取或设置 Menu 的名称。Gets or sets the name of the Menu.

(Inherited from Menu)
RightToLeft RightToLeft RightToLeft RightToLeft

获取或设置控件显示的文本是否从右向左显示。Gets or sets whether the text displayed by the control is displayed from right to left.

Site Site Site Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
Tag Tag Tag Tag

获取或设置与控件关联的用户定义的数据。Gets or sets user-defined data associated with the control.

(Inherited from Menu)

方法

CloneMenu() CloneMenu() CloneMenu() CloneMenu()

创建一个新 MainMenu,它是当前 MainMenu 的副本。Creates a new MainMenu that is a duplicate of the current MainMenu.

CloneMenu(Menu) CloneMenu(Menu) CloneMenu(Menu) CloneMenu(Menu)

复制作为参数被传递到当前 MenuMenuCopies the Menu that is passed as a parameter to the current Menu.

(Inherited from Menu)
CreateMenuHandle() CreateMenuHandle() CreateMenuHandle() CreateMenuHandle()

创建 Menu 的新句柄。Creates a new handle to the Menu.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

处置由 MainMenu 占用的资源(内存除外)。Disposes of the resources, other than memory, used by the MainMenu.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
FindMenuItem(Int32, IntPtr) FindMenuItem(Int32, IntPtr) FindMenuItem(Int32, IntPtr) FindMenuItem(Int32, IntPtr)

获取 MenuItem,它包含指定的值。Gets the MenuItem that contains the value specified.

(Inherited from Menu)
FindMergePosition(Int32) FindMergePosition(Int32) FindMergePosition(Int32) FindMergePosition(Int32)

返回菜单项应插入菜单的位置。Returns the position at which a menu item should be inserted into the menu.

(Inherited from Menu)
GetContextMenu() GetContextMenu() GetContextMenu() GetContextMenu()

获取包含该菜单的 ContextMenuGets the ContextMenu that contains this menu.

(Inherited from Menu)
GetForm() GetForm() GetForm() GetForm()

获取包含该控件的 FormGets the Form that contains this control.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetMainMenu() GetMainMenu() GetMainMenu() GetMainMenu()

获取包含该菜单的 MainMenuGets the MainMenu that contains this menu.

(Inherited from Menu)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
MergeMenu(Menu) MergeMenu(Menu) MergeMenu(Menu) MergeMenu(Menu)

将一个菜单的 MenuItem 对象与当前菜单合并。Merges the MenuItem objects of one menu with the current menu.

(Inherited from Menu)
OnCollapse(EventArgs) OnCollapse(EventArgs) OnCollapse(EventArgs) OnCollapse(EventArgs)

引发 Collapse 事件。Raises the Collapse event.

ProcessCmdKey(Message, Keys) ProcessCmdKey(Message, Keys) ProcessCmdKey(Message, Keys) ProcessCmdKey(Message, Keys)

处理命令键。Processes a command key.

(Inherited from Menu)
ToString() ToString() ToString() ToString()

返回表示 MainMenu 的字符串。Returns a string that represents the MainMenu.

事件

Collapse Collapse Collapse Collapse

当主菜单折叠时发生。Occurs when the main menu collapses.

Disposed Disposed Disposed Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

字段

FindHandle FindHandle FindHandle FindHandle

指定 FindMenuItem(Int32, IntPtr) 方法应搜索一个句柄。Specifies that the FindMenuItem(Int32, IntPtr) method should search for a handle.

(Inherited from Menu)
FindShortcut FindShortcut FindShortcut FindShortcut

指定 FindMenuItem(Int32, IntPtr) 方法应搜索一个快捷方式。Specifies that the FindMenuItem(Int32, IntPtr) method should search for a shortcut.

(Inherited from Menu)

适用于

另请参阅