다음을 통해 공유


MenuCommand(EventHandler, CommandID) 생성자

정의

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

적용 대상

추가 정보