Menu.MenuItems Właściwość

Definicja

Pobiera wartość wskazującą kolekcję obiektów skojarzonych MenuItem z menu.

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

Wartość właściwości

Obiekt Menu.MenuItemCollection reprezentujący listę obiektów przechowywanych MenuItem w menu.

Atrybuty

Przykłady

Poniższy przykład kodu tworzy wystąpienie klasy MainMenupochodnej , i dodaje MenuItem obiekt do kolekcji MenuItem obiektów. Ten przykład wymaga, aby metoda zdefiniowana w tym przykładzie znajdowała się w klasie formularza i wywoływana przez metodę w tej klasie formularza.

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

Uwagi

Za pomocą tej właściwości można uzyskać odwołanie do listy elementów menu, które są obecnie przechowywane w menu. Dla MainMenu obiektów MenuItems i ContextMenu właściwość zawiera całą strukturę menu w kontrolce. MenuItem Dla klasy MenuItems właściwość zawiera listę elementów podrzędnych skojarzonych z elementami MenuItem. Za pomocą odwołania do kolekcji elementów menu dla menu (dostarczonego przez tę właściwość) można dodawać i usuwać elementy menu, określać łączną liczbę elementów menu i czyścić listę elementów menu z kolekcji. Aby uzyskać więcej informacji na temat obsługi kolekcji elementów menu dla menu, zobacz dokumentację System.Windows.Forms.Menu.MenuItemCollection .

Dotyczy

Zobacz też