Поделиться через


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 - пространство имен