Udostępnij przez


Menu.MenuItemCollection.CopyTo(Array, Int32) Metoda

Definicja

Kopiuje całą kolekcję do istniejącej tablicy w określonej lokalizacji w tablicy.

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

Tablica docelowa.

index
Int32

Indeks w tablicy docelowej, w której rozpoczyna się przechowywanie.

Implementuje

Przykłady

Poniższy przykład kodu tworzy tablicę i kopiuje Menu.MenuItemCollection obiekty z dwóch MenuItem obiektów do tablicy. W tym przykładzie zostanie skopiowana tablica MenuItem obiektów do kolekcji kontrolek o ContextMenu nazwie contextMenu1. W tym przykładzie wymagane są dwa MenuItem obiekty zawierające elementy podrzędne o nazwie menuItem1 i 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

Uwagi

Ta metoda umożliwia łączenie MenuItem obiektów z wielu kolekcji w jedną tablicę. Ta funkcja umożliwia łatwe łączenie co najmniej dwóch zestawów elementów menu do użycia w elemecie ContextMenu lub MainMenu.

Dotyczy