MenuCommand(EventHandler, CommandID) 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 MenuCommand 类的新实例。
public:
MenuCommand(EventHandler ^ handler, System::ComponentModel::Design::CommandID ^ command);
public MenuCommand (EventHandler handler, System.ComponentModel.Design.CommandID command);
public MenuCommand (EventHandler? handler, System.ComponentModel.Design.CommandID? command);
new System.ComponentModel.Design.MenuCommand : EventHandler * System.ComponentModel.Design.CommandID -> System.ComponentModel.Design.MenuCommand
Public Sub New (handler As EventHandler, command As CommandID)
参数
- handler
- EventHandler
在用户选择菜单项或工具栏按钮时引发的事件。
- command
- CommandID
将此菜单命令链接到环境菜单的唯一命令 ID。
示例
下面的代码示例创建一个 MenuCommand 对象,配置其属性,并将其添加到 对象 IMenuCommandService 。
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." );
}
};
}
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.");
}
}
<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