다음을 통해 공유


ModelExplorerTreeContainer.AddCommandHandlers 메서드

바로 가기 메뉴에서 메뉴 명령을 찾고 호출하고 제거하기 위한 메서드를 제공합니다.

네임스페이스:  Microsoft.VisualStudio.Modeling.Shell
어셈블리:  Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0(Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0.dll)

구문

‘선언
Public Overridable Sub AddCommandHandlers ( _
    menuCommandService As IMenuCommandService _
)
public virtual void AddCommandHandlers(
    IMenuCommandService menuCommandService
)

매개 변수

설명

이 메서드를 호출 하면 ISelectionService 인터페이스입니다.

기본 클래스 구현은 처리기 등록 되어 있지 않은 경우에 명령 처리기를 추가 합니다. 이 통해 각 명령의 처리를 재정의 하려면 파생 된 클래스입니다. 따라서 파생된 클래스는 기본 클래스를 호출 하기 전에 명령을 추가 해야 합니다.

예제

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

Commands.vsct 파일에 include 문 뒤에 다음 줄이 나타납니다.

#define cmdidMyMenuSample  0x0008

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

guidCmdSet:cmdidMyMenuSampe, guidCommonModelingMenu:grpidExplorerMenuGroup, 0x8020, OI_NOID, BUTTON, DIS_DEF, "&Sample Command";

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

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

ModelExplorerTreeContainer 클래스

Microsoft.VisualStudio.Modeling.Shell 네임스페이스