다음을 통해 공유


Menu.MenuItemCollection.CopyTo 메서드

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

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

구문

‘선언
Public Sub CopyTo ( _
    dest As Array, _
    index As Integer _
)
‘사용 방법
Dim instance As MenuItemCollection
Dim dest As Array
Dim index As Integer

instance.CopyTo(dest, index)
public void CopyTo (
    Array dest,
    int index
)
public:
virtual void CopyTo (
    Array^ dest, 
    int index
) sealed
public final void CopyTo (
    Array dest, 
    int index
)
public final function CopyTo (
    dest : Array, 
    index : int
)

매개 변수

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

설명

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

예제

다음 코드 예제에서는 배열을 만든 다음 두 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에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

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