MenuCommand Class
Represents a Windows menu or toolbar command item.
Assembly: System (in System.dll)
| Name | Description | |
|---|---|---|
![]() | MenuCommand(EventHandler^, CommandID^) | Initializes a new instance of the MenuCommand class. |
| Name | Description | |
|---|---|---|
![]() | Checked | Gets or sets a value indicating whether this menu item is checked. |
![]() | CommandID | Gets the CommandID associated with this menu command. |
![]() | Enabled | Gets a value indicating whether this menu item is available. |
![]() | OleStatus | Gets the OLE command status code for this menu item. |
![]() | Properties | Gets the public properties associated with the MenuCommand. |
![]() | Supported | Gets or sets a value indicating whether this menu item is supported. |
![]() | Visible | Gets or sets a value indicating whether this menu item is visible. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | Invoke() | Invokes the command. |
![]() | Invoke(Object^) | Invokes the command with the given parameter. |
![]() | MemberwiseClone() | |
![]() | OnCommandChanged(EventArgs^) | Raises the CommandChanged event. |
![]() | ToString() | Returns a string representation of this menu command.(Overrides Object::ToString().) |
| Name | Description | |
|---|---|---|
![]() | CommandChanged | Occurs when the menu command changes. |
The MenuCommand class represents information about a Windows menu or toolbar command. The IMenuCommandService interface allows you to add MenuCommand objects to the Visual Studio menu.
This class provides the following members:
An event-handler property to which you can attach an event handler for the command.
A CommandID property that uniquely identifies the command.
An Invoke method that executes the command.
An OnCommandChanged method that can be overridden to handle the event that occurs when a new command is selected.
Boolean flag states that indicate whether the command is Checked, Enabled, Supported, or Visible.
An OleStatus property that indicates the OLE command status code for the command.
An override for the ToString method.
The following code example creates a MenuCommand object, configures its properties, and adds it to the IMenuCommandService.
Create an instance of the Component1 class on your form and open the form in a design environment like Visual Studio. Press the F1 key to invoke the MenuCommand.
#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." ); } }; }
for full access to system resources. Demand values: LinkDemand, InheritanceDemand. Associated state:
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.



