Menu.MenuItemCollection.CopyTo(Array, Int32) Methode

Definition

Kopiert die gesamte Auflistung an einer angegebenen Position innerhalb des Arrays in ein vorhandenes Array.

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)

Parameter

dest
Array

Das Zielarray.

index
Int32

Der Index im Zielarray, an dem der Speicher beginnt.

Implementiert

Beispiele

Im folgenden Codebeispiel wird ein Array erstellt und die Menu.MenuItemCollection Objekte aus zwei MenuItem Objekten in das Array kopiert. Im Beispiel wird dann das Array von MenuItem Objekten in die Steuerelementauflistung für einen ContextMenu benannten contextMenu1Objekt kopiert. Dieses Beispiel erfordert, dass zwei MenuItem Objekte vorhanden sind, die Untermenüelemente mit dem Namen menuItem1 und menuItem2dem Namen enthalten.

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

Hinweise

Mit dieser Methode können Sie Objekte aus mehreren Auflistungen in einem einzigen Array kombinieren MenuItem . Mit diesem Feature können Sie ganz einfach zwei oder mehr Menüelemente für die Verwendung in einem ContextMenu oder mehrere MainMenuMenüelemente kombinieren.

Gilt für: