英語で読む

次の方法で共有


MenuCommand クラス

定義

Windows メニューまたはツール バーのコマンド項目を表します。

C#
public class MenuCommand
C#
[System.Runtime.InteropServices.ComVisible(true)]
public class MenuCommand
継承
MenuCommand
派生
属性

次のコード例では、 オブジェクトを MenuCommand 作成し、そのプロパティを構成し、 に追加します IMenuCommandService

フォーム上に Component1 クラスのインスタンスを作成し、Visual Studio などのデザイン環境でフォームを開きます。 F1 キーを押して を呼び出します MenuCommand

C#
using System;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace CSMenuCommand
{
    [Designer(typeof(CDesigner))]
    public class Component1 : System.ComponentModel.Component
    {
        private System.ComponentModel.Container components = null;

        public Component1(System.ComponentModel.IContainer container)
        {
            container.Add(this);
            InitializeComponent();
        }

        public Component1()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
        }
    }

    public class CDesigner : System.ComponentModel.Design.ComponentDesigner 
    {
        public override void Initialize(IComponent comp) 
        {
            base.Initialize(comp);

            IMenuCommandService mcs = (IMenuCommandService)comp.Site.
                        GetService(typeof(IMenuCommandService));
            MenuCommand mc = new MenuCommand(new EventHandler(OnF1Help), StandardCommands.F1Help);
            mc.Enabled = true;
            mc.Visible = true;
            mc.Supported = true;
            mcs.AddCommand(mc);
            System.Windows.Forms.MessageBox.Show("Initialize() has been invoked.");
        }

        private void OnF1Help(object sender, EventArgs e) 
        {
            System.Windows.Forms.MessageBox.Show("F1Help has been invoked.");
        }
    }
}

注釈

クラスは MenuCommand 、Windows メニューまたはツール バー コマンドに関する情報を表します。 IMenuCommandServiceインターフェイスを使用すると、Visual Studio メニューにオブジェクトを追加MenuCommandできます。

このクラスは、次のメンバーを提供します。

  • コマンドのイベント ハンドラーをアタッチできるイベント ハンドラー プロパティ。

  • CommandIDコマンドを一意に識別するプロパティ。

  • Invokeコマンドを実行するメソッド。

  • OnCommandChanged新しいコマンドが選択されたときに発生するイベントを処理するためにオーバーライドできるメソッド。

  • ブール型フラグはCheckedEnabledSupported、コマンドが 、または Visibleであるかどうかを示す状態です。

  • コマンドの OleStatus OLE コマンドの状態コードを示す プロパティ。

  • メソッドの ToString オーバーライド。

コンストラクター

MenuCommand(EventHandler, CommandID)

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

プロパティ

Checked

メニュー項目がチェックされているかどうかを示す値を取得または設定します。

CommandID

メニュー コマンドに関連付けられている CommandID を取得します。

Enabled

メニュー項目を使用できるかどうかを示す値を取得します。

OleStatus

メニュー項目の OLE コマンド ステータス コードを取得します。

Properties

MenuCommand に関連付けられているパブリック プロパティを取得します。

Supported

メニュー項目がサポートされているかどうかを示す値を取得または設定します。

Visible

メニュー項目を表示するかどうかを示す値を取得または設定します。

メソッド

Equals(Object)

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

(継承元 Object)
GetHashCode()

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

(継承元 Object)
GetType()

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

(継承元 Object)
Invoke()

コマンドを呼び出します。

Invoke(Object)

指定したパラメーターを使用して、コマンドが呼び出されます。

MemberwiseClone()

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

(継承元 Object)
OnCommandChanged(EventArgs)

CommandChanged イベントを発生させます。

ToString()

メニュー コマンドの文字列形式を返します。

イベント

CommandChanged

メニュー コマンドが変更されたときに発生します。

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

こちらもご覧ください