显示快捷菜单的命令。
命名空间: Microsoft.VisualStudio.Modeling.Shell
程序集: Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0(在 Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0.dll 中)
语法
声明
Protected Overrides Function GetMenuCommands As IList(Of MenuCommand)
protected override IList<MenuCommand> GetMenuCommands()
返回值
类型:System.Collections.Generic.IList<MenuCommand>
菜单命令列表。
备注
您可以重写此方法并添加自己的命令。 添加自己定义命令,在自定义 .vsct 文件并调用其在定义自 .cs 文件。
备注
不要向 CommandSet.cs 文件的更改。使用生成生成的设计器的该文件都会重新生成。
示例
本示例将自定义命令添加到快捷菜单。 当用户在生成的设计器的解决方案并右击关系图时,另一个命令,则 验证 (V),显示快捷菜单。
在 Commands.vsct 文件,下面一行在 include 语句之后显示。
#define AssociationSortValidate 0x801
在 Commands.vsct 文件,下面一行在 GENERATED_BUTTONS 后显示。
guidCmdSet:AssociationSortValidate, guidCmdSet:grpidContextMain, 0x0100, OI_NOID, BUTTON, DIS_DEF, "&Validate";
在 VsctComponents 文件夹中,如下 .cs 文件可用。 命名空间和方法有一些项目,则 MenuSample的名称,在它们。
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Shell;
namespace MS.MenuSample
{
internal partial class MenuSampleCommandSet
{
// Define the command. This must be unique and match the value in Commands.vsct.
private const int AssociationSortValidate = 0x801;
// Register event handlers for menu commands when the Domain-Specific Language Designer starts.
// Get the commands defined in the generated code.
protected override IList<System.ComponentModel.Design.MenuCommand> GetMenuCommands()
{
global::System.Collections.Generic.IList<global::System.ComponentModel.Design.MenuCommand> commands = base.GetMenuCommands();
commands.Add(new DynamicStatusMenuCommand(
new EventHandler(OnStatusChangeAssociationSort),
new EventHandler(OnMenuChangeAssociationSort),
CustomCommandId(AssociationSortValidate)));
return commands;
}
// Set whether a command should appear in the shortcut menu by default.
internal void OnStatusChangeAssociationSort(object sender, EventArgs e)
{
MenuCommand command = sender as MenuCommand;
command.Visible = command.Enabled = true;
}
// Perform an Association Sort command on the current selection.
internal void OnMenuChangeAssociationSort(object sender, EventArgs e)
{
MenuCommand command = sender as MenuCommand;
}
// Create local command IDs that are unique.
private CommandID CustomCommandId(int command)
{
return new CommandID(new Guid(Constants.MenuSampleCommandSetId), command);
}
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关详细信息,请参阅通过部分受信任的代码使用库。