次の方法で共有


Menu クラス

定義

注意事項

Menu is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use ToolStripDropDown and ToolStripDropDownMenu instead.

すべてのメニューの基本機能を表します。

このクラスは、.NET Core 3.1 以降のバージョンでは使用できません。 代わりに ToolStripDropDownToolStripDropDownMenu を使用して、 Menu コントロールを置き換えて拡張します。

public ref class Menu abstract : System::ComponentModel::Component
[System.ComponentModel.ListBindable(false)]
public abstract class Menu : System.ComponentModel.Component
[System.ComponentModel.ListBindable(false)]
[System.ComponentModel.Browsable(false)]
[System.Obsolete("`Menu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ToolStripDropDown` and `ToolStripDropDownMenu` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
public abstract class Menu : System.ComponentModel.Component
[<System.ComponentModel.ListBindable(false)>]
type Menu = class
    inherit Component
[<System.ComponentModel.ListBindable(false)>]
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("`Menu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ToolStripDropDown` and `ToolStripDropDownMenu` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
type Menu = class
    inherit Component
Public MustInherit Class Menu
Inherits Component
継承
派生
属性

次のコード例では、派生クラス MenuItemを使用して、フォームのメニュー構造を作成します。 このコード例では、最上位レベルのメニュー項目を表す MenuItem を追加し、それにフォント サイズを選択するためのサブメニュー項目を追加した後、そのメニュー項目に 2 つのサブメニュー項目を追加します。このサブメニュー項目は、アプリケーション内の大小のフォントの選択肢を表します。 この例では、mainMenu1という名前のMainMenu オブジェクトと、menuItem1menuItem2menuItem3menuItem4という名前の 4 つのMenuItem オブジェクトが必要です。

public:
   void CreateMyMenu()
   {
      // Set the caption for the top-level menu item.
      menuItem1->Text = "Edit";
      // Set the caption for the first submenu.
      menuItem2->Text = "Font Size";
      // Set the caption for menuItem2's first submenu.
      menuItem3->Text = "Small";
      // Set the checked property to true since this is the default value.
      menuItem3->Checked = true;
      // Define a shortcut key combination for the menu item.
      menuItem3->Shortcut = Shortcut::CtrlS;
      // Set the caption of the second sub menu item of menuItem2.
      menuItem4->Text = "Large";
      // Define a shortcut key combination for the menu item.
      menuItem4->Shortcut = Shortcut::CtrlL;
      // Set the index of the menu item so it is placed below the first submenu item.
      menuItem4->Index = 1;
      // Add menuItem3 and menuItem4 to menuItem2's list of menu items.
      menuItem2->MenuItems->Add( menuItem3 );
      menuItem2->MenuItems->Add( menuItem4 );
      // Add menuItem2 to menuItem1's list of menu items.
      menuItem1->MenuItems->Add( menuItem2 );
      // Add menuItem1 to the MainMenu for displaying.
      mainMenu1->MenuItems->Add( menuItem1 );
   }
public void CreateMyMenu()
    {
    // Set the caption for the top-level menu item.
    menuItem1.Text = "Edit";
    // Set the caption for the first submenu.
    menuItem2.Text = "Font Size";
    // Set the caption for menuItem2's first submenu.
    menuItem3.Text = "Small";
    // Set the checked property to true since this is the default value.
    menuItem3.Checked = true;
    // Define a shortcut key combination for the menu item.
    menuItem3.Shortcut = Shortcut.CtrlS;
    // Set the caption of the second sub menu item of menuItem2.
    menuItem4.Text = "Large";
    // Define a shortcut key combination for the menu item.
    menuItem4.Shortcut = Shortcut.CtrlL;
    // Set the index of the menu item so it is placed below the first submenu item.
    menuItem4.Index = 1;
    // Add menuItem3 and menuItem4 to menuItem2's list of menu items.
    menuItem2.MenuItems.Add(menuItem3);
    menuItem2.MenuItems.Add(menuItem4);
    // Add menuItem2 to menuItem1's list of menu items.
    menuItem1.MenuItems.Add(menuItem2);
    // Add menuItem1 to the MainMenu for displaying.
    mainMenu1.MenuItems.Add(menuItem1);
    }
Public Sub CreateMyMenu()
    ' Set the caption for the top-level menu item.
    menuItem1.Text = "Edit"
    ' Set the caption for the first submenu.
    menuItem2.Text = "Font Size"
    ' Set the caption for menuItem2's first submenu.
    menuItem3.Text = "Small"
    ' Set the checked property to true since this is the default value.
    menuItem3.Checked = True
    ' Define a shortcut key combination for the menu item.
    menuItem3.Shortcut = Shortcut.CtrlS
    ' Set the caption of the second sub menu item of menuItem2.
    menuItem4.Text = "Large"
    ' Define a shortcut key combination for the menu item.
    menuItem4.Shortcut = Shortcut.CtrlL
    ' Set the index of the menu item so it is placed below the first submenu item.
    menuItem4.Index = 1
    ' Add menuItem3 and menuItem4 to menuItem2's list of menu items.
    menuItem2.MenuItems.Add(menuItem3)
    menuItem2.MenuItems.Add(menuItem4)
    ' Add menuItem2 to menuItem1's list of menu items.
    menuItem1.MenuItems.Add(menuItem2)
    ' Add menuItem1 to the MainMenu for displaying.
    mainMenu1.MenuItems.Add(menuItem1)
End Sub

注釈

このクラスは、.NET Core 3.1 以降のバージョンでは使用できません。 代わりに、ToolStripDropDown および ToolStripDropDownMenu を使用してください。

このクラスは、 MainMenuMenuItem、および ContextMenu クラスの基底クラスです。 このクラスのインスタンスを作成することはできません。 アプリケーションのメニューは、 MenuItem オブジェクトで構成されます。 サブメニュー項目を表す他の MenuItem オブジェクトを含めることができます。 MenuItemオブジェクトは、フォームのメニュー構造全体またはショートカット メニューの表示に使用されるContextMenuとして表示するためのMainMenuに格納できます。 このクラスは、すべてのメニュー クラスに共通する機能を提供します。

多くの基底クラスとは異なり、 Menu クラスはその派生クラスを使用してそのプロパティの多くを定義します。 マルチドキュメント インターフェイス (MDI) アプリケーションでメニューを使用している場合は、 MdiListItem プロパティを使用して、開いている MDI 子フォームの一覧をアプリケーションに表示する MenuItem を指定できます。 MenuItems プロパティには、メニュー クラスに格納MenuItemオブジェクトの一覧が含まれています。 MainMenuまたはContextMenuの場合、このプロパティには表示されるすべてのMenuItem オブジェクトが含まれます。 MenuItemの場合、MenuItems プロパティは、それに関連付けられているサブメニュー項目を表します。

Menu クラスには、すべての派生メニュー クラスに対して提供されるプロパティに加えて、既存のメニューから新しいメニューを作成したり、2 つのメニュー構造を結合したりするためのCloneMenuMergeMenuなどのメソッドも用意されています。

Menu クラスは、入れ子になったクラスのMenu.MenuItemCollectionも定義します。 このクラスは、MenuItems プロパティによって使用されるMenuItem オブジェクトのコレクションを定義します。 Menu.MenuItemCollection クラスのメソッドを使用して、MainMenuContextMenu、またはMenuItemからメニュー項目を追加および削除できます。

コンストラクター

名前 説明
Menu(MenuItem[])
古い.

Menu クラスの新しいインスタンスを初期化します。

フィールド

名前 説明
FindHandle
古い.

FindMenuItem(Int32, IntPtr) メソッドがハンドルを検索することを指定します。

FindShortcut
古い.

FindMenuItem(Int32, IntPtr) メソッドがショートカットを検索することを指定します。

プロパティ

名前 説明
CanRaiseEvents
古い.

コンポーネントがイベントを発生できるかどうかを示す値を取得します。

(継承元 Component)
Container
古い.

IContainerを含むComponentを取得します。

(継承元 Component)
DesignMode
古い.

Componentが現在デザイン モードであるかどうかを示す値を取得します。

(継承元 Component)
Events
古い.

この Componentにアタッチされているイベント ハンドラーの一覧を取得します。

(継承元 Component)
Handle
古い.

メニューのウィンドウ ハンドルを表す値を取得します。

IsParent
古い.

このメニューにメニュー項目が含まれているかどうかを示す値を取得します。 このプロパティは読み取り専用です。

MdiListItem
古い.

複数のドキュメント インターフェイス (MDI) 子フォームの一覧を表示するために使用される MenuItem を示す値を取得します。

MenuItems
古い.

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

Name
古い.

Menuの名前を取得または設定します。

Site
古い.

ISiteComponentを取得または設定します。

(継承元 Component)
Tag
古い.

コントロールに関連付けられているユーザー定義データを取得または設定します。

メソッド

名前 説明
CloneMenu(Menu)
古い.

パラメーターとして渡された Menu を現在の Menuにコピーします。

CreateMenuHandle()
古い.

Menuへの新しいハンドルを作成します。

CreateObjRef(Type)
古い.

リモート オブジェクトとの通信に使用されるプロキシの生成に必要なすべての関連情報を含むオブジェクトを作成します。

(継承元 MarshalByRefObject)
Dispose()
古い.

Componentによって使用されるすべてのリソースを解放します。

(継承元 Component)
Dispose(Boolean)
古い.

Menuによって使用されるメモリ以外のリソースを破棄します。

Equals(Object)
古い.

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
FindMenuItem(Int32, IntPtr)
古い.

指定した値を含む MenuItem を取得します。

FindMergePosition(Int32)
古い.

メニュー項目をメニューに挿入する位置を返します。

GetContextMenu()
古い.

このメニューを含む ContextMenu を取得します。

GetHashCode()
古い.

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetMainMenu()
古い.

このメニューを含む MainMenu を取得します。

GetService(Type)
古い.

ComponentまたはそのContainerによって提供されるサービスを表すオブジェクトを返します。

(継承元 Component)
GetType()
古い.

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
MemberwiseClone()
古い.

現在の Objectの簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)
古い.

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
MergeMenu(Menu)
古い.

1 つのメニューの MenuItem オブジェクトを現在のメニューとマージします。

ProcessCmdKey(Message, Keys)
古い.

コマンド キーを処理します。

ToString()
古い.

Menu コントロールを表すStringを返します。

イベント

名前 説明
Disposed
古い.

コンポーネントが Dispose() メソッドの呼び出しによって破棄されるときに発生します。

(継承元 Component)

適用対象

こちらもご覧ください