Share via


Menu.MenuItemCollection.CopyTo(Array, Int32) Metoda

Definice

Zkopíruje celou kolekci do existujícího pole v zadaném umístění v rámci pole.

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)

Parametry

dest
Array

Cílové pole.

index
Int32

Index v cílovém poli, na kterém začíná ukládání.

Implementuje

Příklady

Následující příklad kódu vytvoří pole a zkopíruje Menu.MenuItemCollection objekty ze dvou MenuItem objektů do pole. Příklad pak zkopíruje pole objektů do kolekce ovládacích MenuItem prvků pro pojmenovanou ContextMenucontextMenu1. Tento příklad vyžaduje, aby existovaly dva MenuItem objekty, které obsahují položky podnabídky s názvem menuItem1 a menuItem2.

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

Poznámky

Tuto metodu můžete použít ke kombinování MenuItem objektů z více kolekcí do jednoho pole. Tato funkce umožňuje snadno zkombinovat dvě nebo více sad položek nabídky pro použití v ContextMenuMainMenunebo .

Platí pro