MainMenu 类

定义

表示窗体的菜单结构。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. 此示例要求您创建一个FormForm1为的。This 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. 若要将MainMenu Form Menu 显示的Form绑定到, 请将分配给的属性。MainMenuTo 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 类的一个新实例。Initializes a new instance of the MainMenu class without any specified menu items.

MainMenu(IContainer)

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

MainMenu(MenuItem[])

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

字段

FindHandle

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

(继承自 Menu)
FindShortcut

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

(继承自 Menu)

属性

CanRaiseEvents

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

(继承自 Component)
Container

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

(继承自 Component)
DesignMode

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

(继承自 Component)
Events

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

(继承自 Component)
Handle

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

(继承自 Menu)
IsParent

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

(继承自 Menu)
MdiListItem

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

(继承自 Menu)
MenuItems

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

(继承自 Menu)
Name

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

(继承自 Menu)
RightToLeft

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

Site

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

(继承自 Component)
Tag

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

(继承自 Menu)

方法

CloneMenu()

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

CloneMenu(Menu)

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

(继承自 Menu)
CreateMenuHandle()

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

CreateObjRef(Type)

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

(继承自 MarshalByRefObject)
Dispose()

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

(继承自 Component)
Dispose(Boolean)

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

Equals(Object)

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

(继承自 Object)
FindMenuItem(Int32, IntPtr)

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

(继承自 Menu)
FindMergePosition(Int32)

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

(继承自 Menu)
GetContextMenu()

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

(继承自 Menu)
GetForm()

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

GetHashCode()

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

(继承自 Object)
GetLifetimeService()

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

(继承自 MarshalByRefObject)
GetMainMenu()

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

(继承自 Menu)
GetService(Type)

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

(继承自 Component)
GetType()

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

(继承自 Object)
InitializeLifetimeService()

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

(继承自 MarshalByRefObject)
MemberwiseClone()

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

(继承自 Object)
MemberwiseClone(Boolean)

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

(继承自 MarshalByRefObject)
MergeMenu(Menu)

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

(继承自 Menu)
OnCollapse(EventArgs)

引发 Collapse 事件。Raises the Collapse event.

ProcessCmdKey(Message, Keys)

处理命令键。Processes a command key.

(继承自 Menu)
ToString()

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

事件

Collapse

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

Disposed

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

(继承自 Component)

适用于

另请参阅