ModelExplorerTreeContainer.AddCommandHandlers メソッド

メソッドをショートカット メニューのメニュー コマンドを見つけて起動し、削除する手順について説明します。

名前空間:  Microsoft.VisualStudio.Modeling.Shell
アセンブリ:  Microsoft.VisualStudio.Modeling.Sdk.Shell.11.0 (Microsoft.VisualStudio.Modeling.Sdk.Shell.11.0.dll 内)

構文

'宣言
Public Overridable Sub AddCommandHandlers ( _
    menuCommandService As IMenuCommandService _
)
public virtual void AddCommandHandlers(
    IMenuCommandService menuCommandService
)

パラメーター

解説

このメソッドは ISelectionService のインターフェイスを開始します。

基本クラスの実装は、ハンドラーが既に登録されていない場合に限りますコマンド ハンドラーを追加します。これは、コマンドの処理をオーバーライドするために派生クラスで使用できるようになります。したがって、派生クラスは基本クラスを呼び出す前にコマンドを追加する必要があります。

この例では、カスタム ショートカット メニューにコマンドを追加します。ユーザーが生成した Designer ソリューションをビルドしてダイアグラムを右クリックすると、1 回の追加、*** Sample Command *** コマンドがショートカット メニューに表示されます。

Commands.vsct ファイルで、次の行に include ステートメントの後に表示されます。

#define cmdidMyMenuSample  0x0008

Commands.vsct ファイルで、次の行は GENERATED_BUTTONS の後に表示されます。

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

VsctComponents のフォルダーで、次の .cs ファイルを使用できます。名前空間とメソッドの一部は、で、プロジェクトの名前 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 名前空間