ショートカット メニューのコマンドが表示されます。
名前空間: 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 ファイルへの変更を追加しないでください。で生成されたデザイナーを作成する場合は、このファイルは再生成します。
例
この例では、カスタム ショートカット メニューにコマンドを追加します。ユーザーが生成した Designer ソリューションをビルドしてダイアグラムを右クリックすると、1 回の追加、 検証 コマンドがショートカット メニューに表示されます。
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 セキュリティ
- 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。