We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

OleMenuCommandService Class

This class derives from the MenuCommandService class and implements IOleCommandTarget. MenuCommandService is the managed class used to add handlers for menu commands and to define verbs.

This API is not CLS-compliant. 


Namespace:  Microsoft.VisualStudio.Shell
Assembly:  Microsoft.VisualStudio.Shell.10.0 (in Microsoft.VisualStudio.Shell.10.0.dll)

public class OleMenuCommandService : MenuCommandService, 

The OleMenuCommandService type exposes the following members.

Public methodOleMenuCommandService(IServiceProvider)Creates a new menu command service.
Public methodOleMenuCommandService(IServiceProvider, IOleCommandTarget)Creates a new menu command service.

Public propertyParentTargetGets or sets the parent command target.
Protected propertyServiceProvider Obsolete. Gets the service provider.
Public propertyVerbsGets a collection of the designer verbs that are currently available. (Inherited from MenuCommandService.)

Public methodAddCommandAdds a command handler to the menu command service. (Inherited from MenuCommandService.)
Public methodAddVerbAdds a verb to the verb table of the MenuCommandService. (Inherited from MenuCommandService.)
Public methodDispose()Releases all resources used by the MenuCommandService. (Inherited from MenuCommandService.)
Protected methodDispose(Boolean)Releases all resources used by the MenuCommandService. (Inherited from MenuCommandService.)
Protected methodEnsureVerbsEnsures that the verb list has been created. (Inherited from MenuCommandService.)
Public methodEqualsDetermines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFindCommand(CommandID)Searches for the MenuCommand associated with the given command ID. (Inherited from MenuCommandService.)
Protected methodFindCommand(Guid, Int32)Searches for the MenuCommand associated with the given command. (Inherited from MenuCommandService.)
Protected methodGetCommandListGets the command list for a given GUID. (Inherited from MenuCommandService.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Protected methodGetServiceGets a reference to the requested service. (Inherited from MenuCommandService.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGlobalInvoke(CommandID)Can be used to invoke any command within Visual Studio. (Overrides MenuCommandService.GlobalInvoke(CommandID).)
Public methodGlobalInvoke(CommandID, Object)Can be used to invoke any command within Visual Studio. (Overrides MenuCommandService.GlobalInvoke(CommandID, Object).)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnCommandsChangedCalled by a menu command when its status has changed. (Overrides MenuCommandService.OnCommandsChanged(MenuCommandsChangedEventArgs).)
Public methodRemoveCommandRemoves the given menu command from the document. (Inherited from MenuCommandService.)
Public methodRemoveVerbRemoves the given verb from the document. (Inherited from MenuCommandService.)
Public methodShowContextMenuShows the shortcut menu with the given command ID at the given location. (Overrides MenuCommandService.ShowContextMenu(CommandID, Int32, Int32).)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public eventMenuCommandsChangedOccurs when the status of a menu command has changed. (Inherited from MenuCommandService.)

Explicit interface implemetationPrivate methodIOleCommandTarget.ExecInfrastructure. Executes the selected command.
Explicit interface implemetationPrivate methodIOleCommandTarget.QueryStatusInfrastructure. Sets command status.

OleMenuCommandService is automatically offered by the Package class (to offer global commands for an entire package), and it is also offered by the WindowPane class (to offer commands for the current window). This offering is always done via the service container, so anyone deriving from the Package or WindowPane classes can remove or replace the default implementation of this class. This class uses several other services. All of these services are optional, so the class's behavior will degrade if one or more services are missing. The following table shows which services are used and for what purpose:




Used to discover the current selection in order to obtain verbs offered by the currently selected designer.


Used to obtain the designer for the currently selected component, if any.


Used to notify Visual Studio that the command status has changed.

Used to execute global commands


Used to show context menus

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.