ModelExplorerTreeContainer.AddCommandHandlers 方法
提供用于从快捷菜单中查找,调用和移除菜单命令。
命名空间: Microsoft.VisualStudio.Modeling.Shell
程序集: Microsoft.VisualStudio.Modeling.Sdk.Shell.11.0(在 Microsoft.VisualStudio.Modeling.Sdk.Shell.11.0.dll 中)
语法
声明
Public Overridable Sub AddCommandHandlers ( _
menuCommandService As IMenuCommandService _
)
public virtual void AddCommandHandlers(
IMenuCommandService menuCommandService
)
参数
- menuCommandService
类型:System.ComponentModel.Design.IMenuCommandService
使用的 IMenuCommandService 接口与命令。
备注
此方法调用 ISelectionService 接口。
,仅当处理程序已未注册,基类实现将命令添加处理程序。 这使派生类重写处理每个命令。 因此,,在调用基类之前,派生类应添加命令。
示例
此示例添加一个自定义命令添加到快捷菜单。 当用户在编辑器中生成的设计器生成解决方案并右击关系图时,一个其他命令, 示例命令,显示快捷菜单。
在 Commands.vsct 文件,下面一行包含在语句之后。
#define cmdidMyMenuSample 0x0008
在 Commands.vsct 文件,下面的行。 GENERATED_BUTTONS 后面。
guidCmdSet:cmdidMyMenuSampe, guidCommonModelingMenu:grpidExplorerMenuGroup, 0x8020, OI_NOID, BUTTON, DIS_DEF, "&Sample Command";
在 VsctComponents 文件夹中,按以下 .cs 文件可用。命名空间和某些方法具有项目, MenuSample 的名称,则它们。
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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。