Share via


Menu.MenuItems 屬性

定義

取得值,指出與功能表相關的 MenuItem 物件集合。

public:
 property System::Windows::Forms::Menu::MenuItemCollection ^ MenuItems { System::Windows::Forms::Menu::MenuItemCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Menu.MenuItemCollection MenuItems { get; }
[<System.ComponentModel.Browsable(false)>]
member this.MenuItems : System.Windows.Forms.Menu.MenuItemCollection
Public ReadOnly Property MenuItems As Menu.MenuItemCollection

屬性值

Menu.MenuItemCollection

Menu.MenuItemCollection,表示儲存在功能表中的 MenuItem 物件清單。

屬性

範例

下列程式碼範例會建立衍生類別的實例, MainMenu 並將 物件加入 MenuItem 其 物件集合 MenuItem 中。 此範例要求在此範例中定義的方法位於表單的 類別內,並由該表單類別中的方法呼叫。

private:
   void InitializeMyMainMenu()
   {
      // Create the MainMenu and the MenuItem to add.
      MainMenu^ mainMenu1 = gcnew MainMenu;
      MenuItem^ menuItem1 = gcnew MenuItem( "&File" );
      
      /* Use the MenuItems property to call the Add method
         to add the MenuItem to the MainMenu menu item collection. */
      mainMenu1->MenuItems->Add( menuItem1 );
      
      // Assign mainMenu1 to the form.
      this->Menu = mainMenu1;
   }
private void InitializeMyMainMenu()
{
   // Create the MainMenu and the MenuItem to add.
   MainMenu mainMenu1 = new MainMenu();
   MenuItem menuItem1 = new MenuItem("&File");
   
   /* Use the MenuItems property to call the Add method
      to add the MenuItem to the MainMenu menu item collection. */
   mainMenu1.MenuItems.Add (menuItem1);

   // Assign mainMenu1 to the form.
   this.Menu = mainMenu1;
}
Private Sub InitializeMyMainMenu()
    ' Create the MainMenu and the MenuItem to add.
    Dim mainMenu1 As New MainMenu()
    Dim menuItem1 As New MenuItem("&File")
       
    ' Use the MenuItems property to call the Add method
    ' to add the MenuItem to the MainMenu menu item collection. 
    mainMenu1.MenuItems.Add(menuItem1)
       
    ' Assign mainMenu1 to the form.
    Me.Menu = mainMenu1
End Sub

備註

您可以使用這個屬性來取得目前儲存在功能表中之功能表項目清單的參考。 對於 MainMenuContextMenu 物件, MenuItems 屬性包含 控制項中的整個功能表結構。 MenuItem針對 類別, MenuItems 屬性包含與 MenuItem 相關聯的子功能表專案清單。 透過參考這個屬性所提供功能表項目的功能表項目集合 () ,您可以新增和移除功能表項目、決定功能表項目的總數,以及清除集合中的功能表項目清單。 如需維護功能表功能表項目集合的詳細資訊,請參閱 System.Windows.Forms.Menu.MenuItemCollection 檔。

適用於

另請參閱