MenuCommand イベント


関連項目
MenuCommand クラスSystem.ComponentModel.Design 名前空間
StandardCommands
IMenuCommandService インターフェイス
CommandID クラス
その他の技術情報
Windows フォームのデザイナ コマンドと DesignerAction オブジェクト モデルMenuCommand クラス
アセンブリ: System (system.dll 内)


MenuCommand クラスは、Windows のメニューまたはツール バーのコマンドに関する情報を表します。IMenuCommandService インターフェイスを使用すると、MenuCommand オブジェクトを Visual Studio .NET のメニューに追加できます。
-
新しいコマンドが選択されたときに発生するイベントを処理するためにオーバーライドできる OnCommandChanged メソッド。
-
コマンドが Checked、Enabled、Supported、または Visible のいずれの状態であるかを示すブール値のフラグ。
![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、SharedState です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |

MenuCommand オブジェクトを作成し、そのプロパティを設定して IMenuCommandService に追加するコード例を次に示します。
Component1 クラスのインスタンスをフォームで作成し、Visual Studio のようなデザイン環境でそのフォームを開きます。F1 キーを押して MenuCommand を呼び出します。
Imports System Imports System.ComponentModel Imports System.ComponentModel.Design Namespace VbMenuCommand <Designer(GetType(CDesigner))> _ Public Class Component1 Inherits System.ComponentModel.Component Private components As System.ComponentModel.Container = Nothing Public Sub New(ByVal container As System.ComponentModel.IContainer) container.Add(Me) InitializeComponent() End Sub Public Sub New() InitializeComponent() End Sub Private Sub InitializeComponent() End Sub End Class <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Public Class CDesigner Inherits System.ComponentModel.Design.ComponentDesigner Public Overrides Sub Initialize(ByVal comp As IComponent) MyBase.Initialize(comp) Dim mcs As IMenuCommandService = CType(comp.Site.GetService(GetType(IMenuCommandService)), IMenuCommandService) Dim mc As New MenuCommand(New EventHandler(AddressOf OnF1Help), StandardCommands.F1Help) mc.Enabled = True mc.Visible = True mc.Supported = True mcs.AddCommand(mc) System.Windows.Forms.MessageBox.Show("Initialize() has been invoked.") End Sub Private Sub OnF1Help(ByVal sender As Object, ByVal e As EventArgs) System.Windows.Forms.MessageBox.Show("F1Help has been invoked.") End Sub End Class End Namespace
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(); } } [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 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."); } } }
#using <system.dll> #using <system.design.dll> #using <system.windows.forms.dll> using namespace System; using namespace System::ComponentModel; using namespace System::ComponentModel::Design; using namespace System::Security::Permissions; namespace CppMenuCommand { public ref class CDesigner: public ComponentDesigner { public: [PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")] virtual void Initialize( IComponent^ comp ) override { ComponentDesigner::Initialize( comp ); IMenuCommandService^ mcs = static_cast<IMenuCommandService^>(comp->Site->GetService( IMenuCommandService::typeid )); MenuCommand^ mc = gcnew MenuCommand( gcnew EventHandler( this, &CDesigner::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." ); } }; }


System.ComponentModel.Design.MenuCommand
System.ComponentModel.Design.DesignerVerb


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


MenuCommand コンストラクタ
アセンブリ: System (system.dll 内)

Dim handler As EventHandler Dim command As CommandID Dim instance As New MenuCommand(handler, command)
public MenuCommand ( EventHandler handler, CommandID command )
public: MenuCommand ( EventHandler^ handler, CommandID^ command )
public MenuCommand ( EventHandler handler, CommandID command )

MenuCommand オブジェクトを作成し、そのプロパティを設定して IMenuCommandService オブジェクトに追加するコード例を次に示します。
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Public Class CDesigner Inherits System.ComponentModel.Design.ComponentDesigner Public Overrides Sub Initialize(ByVal comp As IComponent) MyBase.Initialize(comp) Dim mcs As IMenuCommandService = CType(comp.Site.GetService(GetType(IMenuCommandService)), IMenuCommandService) Dim mc As New MenuCommand(New EventHandler(AddressOf OnF1Help), StandardCommands.F1Help) mc.Enabled = True mc.Visible = True mc.Supported = True mcs.AddCommand(mc) System.Windows.Forms.MessageBox.Show("Initialize() has been invoked.") End Sub Private Sub OnF1Help(ByVal sender As Object, ByVal e As EventArgs) System.Windows.Forms.MessageBox.Show("F1Help has been invoked.") End Sub End Class
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 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."); } }
public ref class CDesigner: public ComponentDesigner { public: [PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")] virtual void Initialize( IComponent^ comp ) override { ComponentDesigner::Initialize( comp ); IMenuCommandService^ mcs = static_cast<IMenuCommandService^>(comp->Site->GetService( IMenuCommandService::typeid )); MenuCommand^ mc = gcnew MenuCommand( gcnew EventHandler( this, &CDesigner::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." ); } }; }

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


MenuCommand プロパティ

名前 | 説明 | |
---|---|---|
![]() | Checked | メニュー項目がチェックされているかどうかを示す値を取得または設定します。 |
![]() | CommandID | メニュー コマンドに関連付けられている CommandID を取得します。 |
![]() | Enabled | メニュー項目を使用できるかどうかを示す値を取得します。 |
![]() | OleStatus | メニュー項目の OLE コマンド ステータス コードを取得します。 |
![]() | Properties | MenuCommand に関連付けられているパブリック プロパティを取得します。 |
![]() | Supported | メニュー項目がサポートされているかどうかを示す値を取得または設定します。 |
![]() | Visible | メニュー項目を表示するかどうかを示す値を取得または設定します。 |

関連項目
MenuCommand クラスSystem.ComponentModel.Design 名前空間
StandardCommands
IMenuCommandService インターフェイス
CommandID クラス
その他の技術情報
Windows フォームのデザイナ コマンドと DesignerAction オブジェクト モデルMenuCommand メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | Invoke | オーバーロードされます。 コマンドを呼び出します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | オーバーライドされます。 メニュー コマンドの文字列形式を返します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
![]() | OnCommandChanged | CommandChanged イベントを発生させます。 |

関連項目
MenuCommand クラスSystem.ComponentModel.Design 名前空間
StandardCommands
IMenuCommandService インターフェイス
CommandID クラス
その他の技術情報
Windows フォームのデザイナ コマンドと DesignerAction オブジェクト モデルMenuCommand メンバ
Windows メニューまたはツール バーのコマンド項目を表します。
MenuCommand データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Checked | メニュー項目がチェックされているかどうかを示す値を取得または設定します。 |
![]() | CommandID | メニュー コマンドに関連付けられている CommandID を取得します。 |
![]() | Enabled | メニュー項目を使用できるかどうかを示す値を取得します。 |
![]() | OleStatus | メニュー項目の OLE コマンド ステータス コードを取得します。 |
![]() | Properties | MenuCommand に関連付けられているパブリック プロパティを取得します。 |
![]() | Supported | メニュー項目がサポートされているかどうかを示す値を取得または設定します。 |
![]() | Visible | メニュー項目を表示するかどうかを示す値を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | Invoke | オーバーロードされます。 コマンドを呼び出します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | オーバーライドされます。 メニュー コマンドの文字列形式を返します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
![]() | OnCommandChanged | CommandChanged イベントを発生させます。 |


関連項目
MenuCommand クラスSystem.ComponentModel.Design 名前空間
StandardCommands
IMenuCommandService インターフェイス
CommandID クラス
その他の技術情報
Windows フォームのデザイナ コマンドと DesignerAction オブジェクト モデル- MenuCommandのページへのリンク