次の方法で共有


Menu.MenuItems プロパティ

メニューに関連付けられている MenuItem オブジェクトのコレクションを示す値を取得します。

Public ReadOnly Property MenuItems As Menu.MenuItemCollection
[C#]
public Menu.MenuItemCollection MenuItems {get;}
[C++]
public: __property Menu.MenuItemCollection* get_MenuItems();
[JScript]
public function get MenuItems() : Menu.MenuItemCollection;

プロパティ値

メニューに格納された MenuItem オブジェクトのリストを表す System.Windows.Forms.Menu.MenuItemCollection

解説

このプロパティを使用して、現在メニューに格納されているメニュー項目のリストへの参照を取得できます。 MainMenu オブジェクトと ContextMenu オブジェクトの場合、 MenuItems プロパティにはコントロールの完全なメニュー構造が格納されています。 MenuItem クラスの場合、 MenuItems プロパティには MenuItem に関連付けられているサブメニュー項目のリストが格納されています。(このプロパティによって提供される) メニューのメニュー項目のコレクションへの参照を使用して、メニュー項目を追加したり削除したり、メニュー項目の合計数を決定したり、コレクションからメニュー項目のリストを削除できます。メニューのメニュー項目のコレクションの維持に関する詳細については、 System.Windows.Forms.Menu.MenuItemCollection ドキュメントのトピックを参照してください。

使用例

[Visual Basic, C#, C++] 派生クラス MainMenu のインスタンスを作成し、 MenuItem オブジェクトのコレクションに MenuItem オブジェクトを追加する例を次に示します。この例では、例の中で定義されているメソッドが、フォームのクラス内にあり、そのフォーム クラスのメソッドで呼び出されることを前提にしています。

 
Private Sub InitializeMyMainMenu()
    ' Create the MainMenu and the MenuItem to add.
    Dim mainMenu1 As New MainMenu()
    Dim menuItem1 As New MenuItem("&File")
       
    ' Use the MenuItems property to call the Add method
    ' to add the MenuItem to the MainMenu menu item collection. 
    mainMenu1.MenuItems.Add(menuItem1)
       
    ' Assign mainMenu1 to the form.
    Me.Menu = mainMenu1
End Sub


[C#] 
private void InitializeMyMainMenu()
{
   // Create the MainMenu and the MenuItem to add.
   MainMenu mainMenu1 = new MainMenu();
   MenuItem menuItem1 = new MenuItem("&File");
   
   /* Use the MenuItems property to call the Add method
      to add the MenuItem to the MainMenu menu item collection. */
   mainMenu1.MenuItems.Add (menuItem1);

   // Assign mainMenu1 to the form.
   this.Menu = mainMenu1;
}


[C++] 
private:
 void InitializeMyMainMenu()
 {
    // Create the MainMenu and the MenuItem to add.
    MainMenu* mainMenu1 = new MainMenu();
    MenuItem* menuItem1 = new MenuItem(S"&File");
    
    /* Use the MenuItems property to call the Add method
       to add the MenuItem to the MainMenu menu item collection. */
    mainMenu1->MenuItems->Add (menuItem1);
 
    // Assign mainMenu1 to the form.
    this->Menu = mainMenu1;
 }
 

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

Menu クラス | Menu メンバ | System.Windows.Forms 名前空間 | MainMenu | ContextMenu | MenuItem | System.Windows.Forms.Menu.MenuItemCollection