Menu.MenuItemCollection.CopyTo メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As MenuItemCollection Dim dest As Array Dim index As Integer instance.CopyTo(dest, index)

このメソッドを使用すると、複数のコレクションの MenuItem オブジェクトを組み合わせて単一の配列にコピーできます。この機能により、ContextMenu または MainMenu で使用するために、メニュー項目のグループを簡単に組み合わせることができます。

配列を作成し、その配列に 2 つの MenuItem オブジェクトから Menu.MenuItemCollection オブジェクトをコピーするコード例を次に示します。次に、MenuItem オブジェクトの配列が、contextMenu1 という名前の ContextMenu コントロール コレクションにコピーされます。この例では、2 つのサブメニュー項目 menuItem1 と menuItem2 を含む 2 つの MenuItem オブジェクトが作成されている必要があります。
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
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: 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 ); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からMenu.MenuItemCollection.CopyTo メソッドを検索する場合は、下記のリンクをクリックしてください。

- Menu.MenuItemCollection.CopyTo メソッドのページへのリンク