Menu.MenuItemCollection.CopyTo(Array, Int32) Methode

Definitie

Hiermee kopieert u de hele verzameling naar een bestaande matrix op een opgegeven locatie in de matrix.

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)

Parameters

dest
Array

De doelmatrix.

index
Int32

De index in de doelmatrix waarop de opslag begint.

Implementeringen

Voorbeelden

In het volgende codevoorbeeld wordt een matrix gemaakt en worden de Menu.MenuItemCollection objecten van twee MenuItem objecten gekopieerd naar de matrix. In het voorbeeld wordt vervolgens de matrix met MenuItem objecten gekopieerd naar de besturingselementverzameling voor een ContextMenu benoemde.contextMenu1 Dit voorbeeld vereist dat er twee MenuItem objecten zijn die submenu-items met de naam en menuItem1menuItem2.

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

Opmerkingen

U kunt deze methode gebruiken om objecten uit meerdere verzamelingen te combineren MenuItem tot één matrix. Met deze functie kunt u eenvoudig twee of meer sets menu-items combineren voor gebruik in een ContextMenu of MainMenu.

Van toepassing op