다음을 통해 공유


Menu.MenuItemCollection.AddRange 메서드

이전에 만든 MenuItem 개체의 배열을 컬렉션에 추가합니다.

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

구문

‘선언
Public Overridable Sub AddRange ( _
    items As MenuItem() _
)
‘사용 방법
Dim instance As MenuItemCollection
Dim items As MenuItem()

instance.AddRange(items)
public virtual void AddRange (
    MenuItem[] items
)
public:
virtual void AddRange (
    array<MenuItem^>^ items
)
public void AddRange (
    MenuItem[] items
)
public function AddRange (
    items : MenuItem[]
)

매개 변수

  • items
    컬렉션에 추가할 메뉴 항목을 나타내는 MenuItem 개체의 배열입니다.

설명

Add 메서드를 사용하면 각 MenuItem을 컬렉션에 직접 추가하지 않고 이전에 만든 MenuItem 개체의 그룹을 컬렉션에 신속하게 추가할 수 있습니다. 컬렉션에 이미 MenuItem 개체가 있는 경우, 이 메서드를 호출하면 새 MenuItem 개체가 컬렉션의 끝에 추가됩니다.

예제

다음 코드 예제에서는 배열을 만든 다음 두 MenuItem 개체에서 해당 배열로 Menu.MenuItemCollection 개체를 복사합니다. 그런 다음 이 예제에서는 MenuItem 개체의 배열을 contextMenu1이라는 ContextMenu의 컨트롤 컬렉션에 복사합니다. 이 예제에서는 menuItem1menuItem2라는 하위 메뉴 항목이 들어 있는 두 개의 MenuItem 개체가 있어야 합니다.

Private Sub CopyMyMenus()
    ' Create empty array to store MenuItem objects.
    Dim myItems(menuItem1.MenuItems.Count + menuItem2.MenuItems.Count) As MenuItem
       
    ' Copy elements of the first MenuItem collection to array.
    menuItem1.MenuItems.CopyTo(myItems, 0)
    ' Copy elements of the second MenuItem collection, after the first set.
    menuItem2.MenuItems.CopyTo(myItems, myItems.Length)
       
    ' Add the array to the menu item collection of the ContextMenu.
    contextMenu1.MenuItems.AddRange(myItems)
End Sub
private void CopyMyMenus()
{
   // Create empty array to store MenuItem objects.
   MenuItem[] myItems = 
      new MenuItem[menuItem1.MenuItems.Count + menuItem2.MenuItems.Count];
   
   // Copy elements of the first MenuItem collection to array.
   menuItem1.MenuItems.CopyTo(myItems, 0);
   // Copy elements of the second MenuItem collection, after the first set.
   menuItem2.MenuItems.CopyTo(myItems, myItems.Length);

   // Add the array to the menu item collection of the ContextMenu.
   contextMenu1.MenuItems.AddRange(myItems);
}
private:
   void CopyMyMenus()
   {
      // Create empty array to store MenuItem objects.
      array<MenuItem^>^ myItems = gcnew array<MenuItem^>(
         menuItem1->MenuItems->Count + menuItem2->MenuItems->Count );
      
      // Copy elements of the first MenuItem collection to array.
      menuItem1->MenuItems->CopyTo( myItems, 0 );
      // Copy elements of the second MenuItem collection, after the first set.
      menuItem2->MenuItems->CopyTo( myItems, myItems->Length );
      
      // Add the array to the menu item collection of the ContextMenu.
      contextMenu1->MenuItems->AddRange( myItems );
   }

플랫폼

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에서 지원

참고 항목

참조

Menu.MenuItemCollection 클래스
Menu.MenuItemCollection 멤버
System.Windows.Forms 네임스페이스
Add
CopyTo