Menu.MenuItemCollection.CopyTo(Array, Int32) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
コレクション全体を、配列内の指定した位置にある既存の配列にコピーします。
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)
パラメーター
- dest
- Array
コピー先の配列。
- index
- Int32
格納の開始位置となるコピー先配列内のインデックス。
実装
例
次のコード例では、配列を作成し、 Menu.MenuItemCollection オブジェクトを 2 つの MenuItem オブジェクトから配列にコピーします。 次に、MenuItem オブジェクトの配列を、ContextMenuという名前のcontextMenu1のコントロール コレクションにコピーします。 この例では、MenuItem と menuItem1 という名前のサブメニュー項目を含む 2 つの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
注釈
このメソッドを使用すると、複数のコレクション MenuItem オブジェクトを 1 つの配列に結合できます。 この機能を使用すると、 ContextMenu または MainMenuで使用する 2 つ以上のメニュー項目セットを簡単に組み合わせることができます。