ModelExplorerTreeContainer.AddCommandHandlers Method
Provides methods to find, invoke, and remove menu commands from the shortcut menu.
Namespace: Microsoft.VisualStudio.Modeling.Shell
Assembly: Microsoft.VisualStudio.Modeling.Sdk.Shell.10.0 (in Microsoft.VisualStudio.Modeling.Sdk.Shell.10.0.dll)
Syntax
声明
Public Overridable Sub AddCommandHandlers ( _
menuCommandService As IMenuCommandService _
)
public virtual void AddCommandHandlers(
IMenuCommandService menuCommandService
)
public:
virtual void AddCommandHandlers(
IMenuCommandService^ menuCommandService
)
abstract AddCommandHandlers :
menuCommandService:IMenuCommandService -> unit
override AddCommandHandlers :
menuCommandService:IMenuCommandService -> unit
public function AddCommandHandlers(
menuCommandService : IMenuCommandService
)
Parameters
- menuCommandService
Type: System.ComponentModel.Design.IMenuCommandService
The IMenuCommandService interface to use with the commands.
Remarks
This method invokes the ISelectionService interface.
Base class implementation adds command handlers only if a handler is not already registered. This enables derived classes to override the handling of each command. Therefore, derived classes should add commands before they call the base class.
Examples
This example adds a custom command to the shortcut menu. When a user builds a solution in the generated designer and right-clicks the diagram, one additional command, Sample Command, appears in the shortcut menu.
In the Commands.vsct file, the following line appears after the include statements.
#define cmdidMyMenuSample 0x0008
In the Commands.vsct file, the following line appears after GENERATED_BUTTONS.
guidCmdSet:cmdidMyMenuSampe, guidCommonModelingMenu:grpidExplorerMenuGroup, 0x8020, OI_NOID, BUTTON, DIS_DEF, "&Sample Command";
Within the VsctComponents folder, the following .cs file is available.The namespace and some of the methods have the name of the project, MenuSample, in them.
using DslModeling = global::Microsoft.VisualStudio.Modeling;
using DslShell = global::Microsoft.VisualStudio.Modeling.Shell;
using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;
using System;
using System.ComponentModel.Design;
using System.Windows.Forms;
namespace MS.MenuSample
{
internal partial class MenuSampleExplorer
{
public override void AddCommandHandlers(System.ComponentModel.Design.IMenuCommandService menuCommandService)
{
menuCommandService.AddCommand(new DslShell::DynamicStatusMenuCommand(
new EventHandler(OnStatusMyMenuSample),
new EventHandler(OnMenuMyMenuSample),
Constants.MyMenuSampleCommand));
base.AddCommandHandlers(menuCommandService);
}
private void OnStatusMyMenuSample(object sender, EventArgs e)
{
System.ComponentModel.Design.MenuCommand cmd = sender as System.ComponentModel.Design.MenuCommand;
cmd.Enabled = cmd.Visible = true;
}
private void OnMenuMyMenuSample(object sender, EventArgs e)
{
MessageBox.Show("Place for you to act when user chooses this menu item");
}
}
internal static partial class Constants
{
private const int cmdidMyMenuSample = 0x0008;
public static readonly CommandID MyMenuSampleCommand = new CommandID(new Guid(MenuSampleCommandSetId), Constants.cmdidMyMenuSample);
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.