다음을 통해 공유


CommandSet.GetMenuCommands 메서드

바로 가기 메뉴에 명령을 표시합니다.

네임스페이스:  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 파일에 변경 내용을 추가 하지 마십시오.이 파일에는 생성 된 디자이너를 빌드할 때마다 다시 생성 됩니다.

예제

바로 가기 메뉴에 사용자 지정 명령을 추가 하는이 예제입니다. 생성 된 디자이너에서 솔루션 빌드를 하나 추가 명령을 다이어그램을 마우스 오른쪽 단추로 클릭 하면 유효성 검사, 바로 가기 메뉴에 나타납니다.

Commands.vsct 파일에서 다음 줄 뒤에 표시 된 include 문.

#define AssociationSortValidate 0x801

Commands.vsct 파일에 다음 줄은 GENERATED_BUTTONS 후 나타납니다.

guidCmdSet:AssociationSortValidate, guidCmdSet:grpidContextMain, 0x0100, OI_NOID, BUTTON, DIS_DEF, "&Validate";

.Cs 파일을 VsctComponents 폴더에서 사용할 수 있습니다. 네임 스페이스 및 메서드 중 일부는 해당 프로젝트의 이름을 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 네임스페이스