Menu.MenuItemCollection.CopyTo(Array, Int32) 메서드

정의

배열 내의 지정된 위치에서 기존 배열로 전체 컬렉션을 복사합니다.

public:
 virtual void CopyTo(Array ^ dest, int index);
public void CopyTo (Array dest, int index);
abstract member CopyTo : Array * int -> unit
override this.CopyTo : Array * int -> unit
Public Sub CopyTo (dest As Array, index As Integer)

매개 변수

dest
Array

대상 배열입니다.

index
Int32

저장을 시작할 대상 배열의 인덱스입니다.

구현

예제

다음 코드 예제에서는 배열을 만들고 두 MenuItem 개체의 Menu.MenuItemCollection 개체를 배열에 복사합니다. 그런 다음, 개체 배열 MenuItem 을 명명contextMenu1된 컨트롤 컬렉션에 복사합니다ContextMenu. 이 예제에서는 명명 menuItem1 된 하위 메뉴 항목과 menuItem2하위 메뉴 항목을 포함하는 두 개의 MenuItem 개체가 있어야 합니다.

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 );
   }
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 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

설명

이 메서드를 사용하여 여러 컬렉션의 개체를 단일 배열로 결합 MenuItem 할 수 있습니다. 이 기능을 사용하면 하나 이상의 MainMenu메뉴 항목 ContextMenu 집합을 쉽게 결합할 수 있습니다.

적용 대상