Represents a Windows menu or toolbar command item.
For a list of all members of this type, see MenuCommand Members.
System.Object
System.ComponentModel.Design.MenuCommand
System.ComponentModel.Design.DesignerVerb
[Visual Basic] <ComVisible(True)> Public Class MenuCommand [C#] [ComVisible(true)] public class MenuCommand [C++] [ComVisible(true)] public __gc class MenuCommand [JScript] public ComVisible(true) class MenuCommand
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
MenuCommand represents information about a Windows menu or toolbar command. The IMenuCommandService interface allows you to add MenuCommand objects to the Visual Studio .NET menu.
This class provides the following members:
[Visual Basic, C#, C++] This example creates a MenuCommand object, configures its properties, and adds it to a IMenuCommandService object.
[Visual Basic] ' This example illustrates how to add a command of type StandardCommand to a ' service of type IMenuCommandService. It defines a class that is a designer ' to a component, called CDesigner. Then it creates a MenuCommand object using ' one of the commands in the StandardCommands class. Finally, it sets several ' of the properties in the MenuCommand object and adds the MenuCommand object ' to the MenuCommandService object. 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 OnReplace), StandardCommands.Group) mc.Enabled = True mc.Visible = True mc.Supported = True mcs.AddCommand(mc) System.Windows.Forms.MessageBox.Show("Initialize() has been invoked.") End Sub 'Initialize Private Sub OnReplace(ByVal sender As Object, ByVal e As EventArgs) System.Windows.Forms.MessageBox.Show("Replace() has been invoked.") End Sub 'OnReplace End Class 'CDesigner [C#] /* This example illustrates how to add a command of type StandardCommand to a service of type IMenuCommandService. It defines a class that is a designer to a component, called CDesigner. Then it creates a MenuCommand object using one of the commands in the StandardCommands class. Finally, it sets several of the properties in the MenuCommand object and adds the MenuCommand object to the MenuCommandService object. */ 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(OnReplace),StandardCommands.Group); mc.Enabled = true; mc.Visible = true; mc.Supported = true; mcs.AddCommand(mc); System.Windows.Forms.MessageBox.Show("Initialize() has been invoked."); } private void OnReplace(object sender, EventArgs e) { System.Windows.Forms.MessageBox.Show("Replace() has been invoked."); } } // End Class Component1 [C++] /* This example illustrates how to add a command of type StandardCommand to a service of type IMenuCommandService. It defines a class that is a designer to a component, called CDesigner. Then it creates a MenuCommand object using one of the commands in the StandardCommands class. Finally, it sets several of the properties in the MenuCommand object and adds the MenuCommand object to the MenuCommandService object. */ public __gc class CDesigner : public ComponentDesigner { public: void Initialize(IComponent* comp) { ComponentDesigner::Initialize(comp); IMenuCommandService* mcs = static_cast<IMenuCommandService*>(comp->Site->GetService(__typeof(IMenuCommandService))); MenuCommand* mc = new MenuCommand(new EventHandler(this, OnReplace), StandardCommands::Group); mc->Enabled = true; mc->Visible = true; mc->Supported = true; mcs->AddCommand(mc); System::Windows::Forms::MessageBox::Show(S"Initialize() has been invoked."); } private: void OnReplace(Object* sender, EventArgs* e) { System::Windows::Forms::MessageBox::Show(S"Replace() has been invoked."); } }; // End Class CDesigner
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System.ComponentModel.Design
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
MenuCommand Members | System.ComponentModel.Design Namespace | StandardCommands | IMenuCommandService | CommandID