MenuCommand Constructor (EventHandler^, CommandID^)

 

Initializes a new instance of the MenuCommand class.

Namespace:   System.ComponentModel.Design
Assembly:  System (in System.dll)

public:
MenuCommand(
	EventHandler^ handler,
	CommandID^ command
)

Parameters

handler
Type: System::EventHandler^

The event to raise when the user selects the menu item or toolbar button.

command
Type: System.ComponentModel.Design::CommandID^

The unique command ID that links this menu command to the environment's menu.

The following code example creates a MenuCommand object, configures its properties, and adds it to an IMenuCommandService object.

   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." );
      }
   };
}

.NET Framework
Available since 1.1
Return to top
Show: