다음을 통해 공유


Menu.MenuItems 속성

해당 메뉴와 연결된 MenuItem 개체의 컬렉션을 나타내는 값을 가져옵니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public ReadOnly Property MenuItems As MenuItemCollection
‘사용 방법
Dim instance As Menu
Dim value As MenuItemCollection

value = instance.MenuItems
public MenuItemCollection MenuItems { get; }
public:
property MenuItemCollection^ MenuItems {
    MenuItemCollection^ get ();
}
/** @property */
public MenuItemCollection get_MenuItems ()
public function get MenuItems () : MenuItemCollection

속성 값

메뉴에 저장된 MenuItem 개체의 목록을 나타내는 System.Windows.Forms.Menu.MenuItemCollection입니다.

설명

이 속성을 사용하면 현재 메뉴에 저장된 메뉴 항목의 목록에 대한 참조를 가져올 수 있습니다. MainMenuContextMenu 개체의 경우, MenuItems 속성에는 컨트롤의 전체 메뉴 구조가 포함되어 있습니다. MenuItem 클래스의 경우, MenuItems 속성에는 MenuItem과 연결된 하위 메뉴 항목의 목록이 포함되어 있습니다. 이 속성에서 제공되는 메뉴의 메뉴 항목 컬렉션에 대한 참조를 사용하여 메뉴 항목을 추가 및 제거하고, 메뉴 항목의 전체 개수를 확인하고, 컬렉션에서 메뉴 항목의 목록을 지울 수 있습니다. 메뉴의 메뉴 항목 컬렉션 유지 관리에 대한 자세한 내용은 System.Windows.Forms.Menu.MenuItemCollection 설명서를 참조하십시오.

예제

다음 예제에서는 파생 클래스인 MainMenu의 인스턴스를 만들고 MenuItem 개체의 컬렉션에 MenuItem 개체를 추가합니다. 이 예제에서는 정의된 메서드가 폼 클래스 내에 배치되어 해당 폼 클래스의 메서드에 의해 호출되어야 합니다.

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
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:
   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.get_MenuItems().Add(menuItem1);

    // Assign mainMenu1 to the form.
    this.set_Menu(mainMenu1);
} //InitializeMyMainMenu

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Menu 클래스
Menu 멤버
System.Windows.Forms 네임스페이스
MainMenu 클래스
ContextMenu 클래스
MenuItem
System.Windows.Forms.Menu.MenuItemCollection