CommandSet.GetMenuCommands 方法

显示在快捷菜单上的命令。

命名空间:  Microsoft.VisualStudio.Modeling.Shell
程序集:  Microsoft.VisualStudio.Modeling.Sdk.Shell.11.0(在 Microsoft.VisualStudio.Modeling.Sdk.Shell.11.0.dll 中)

语法

声明
Protected Overrides Function GetMenuCommands As IList(Of MenuCommand)
protected override IList<MenuCommand> GetMenuCommands()

返回值

类型:System.Collections.Generic.IList<MenuCommand>
菜单命令列表。

备注

可以重写此方法和添加拥有命令。若要添加拥有命令,请定义它们在自定义 .vsct 文件调用这些方法在自定义 .cs 文件。

说明说明

不要对 CommandSet.cs 文件。您生成一个生成的设计器的此文件每次重新生成。

示例

此示例添加一个自定义命令添加到快捷菜单。当用户在编辑器中生成的设计器生成解决方案并右击关系图时,一个其他命令, 验证,显示快捷菜单。

在 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 安全性

请参见

参考

CommandSet 类

Microsoft.VisualStudio.Modeling.Shell 命名空间