MainMenu MainMenu MainMenu MainMenu Class

定義

表示表單的功能表結構。Represents the menu structure of a form. 雖然 MenuStrip 會取代並且將功能加入至之前版本的 MainMenu 控制項;不過,也可以選擇保留 MainMenu,以提供回溯相容性 (Backward Compatibility) 以及供未來使用。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, MainMenu並將MenuItem兩個物件指派至, 並將它系結至表單。The following code example creates a MainMenu, assigns two MenuItem objects to the MainMenu and binds it to a form. 這個範例需要您已Form建立名Form1為的。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. Form Menu MainMenu 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() 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

取得包含 IContainerComponentGets 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

取得值,表示功能表的視窗控制代碼 (Window 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)

將以參數傳遞的 Menu 複製到目前的 MenuCopies the Menu that is passed as a parameter to the current Menu.

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

為功能表建立新的控制代碼。Creates a new handle to the Menu.

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

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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)

取得包含指定值的 MenuItemGets 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()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。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 的淺層複本 (Shallow Copy)。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)

適用於

另請參閱