Metoda ModelExplorerTreeContainer.AddCommandHandlers —
Zapewnia metody znajdowania, wywoływać i usuwanie menu poleceń z menu skrótów.
Przestrzeń nazw: Microsoft.VisualStudio.Modeling.Shell
Zestaw: Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0 (w Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0.dll)
Składnia
'Deklaracja
Public Overridable Sub AddCommandHandlers ( _
menuCommandService As IMenuCommandService _
)
public virtual void AddCommandHandlers(
IMenuCommandService menuCommandService
)
Parametry
- menuCommandService
Typ: System.ComponentModel.Design.IMenuCommandService
IMenuCommandService Interfejsu do użycia z poleceniami.
Uwagi
Ta metoda wywołuje ISelectionService interfejsu.
Implementacja klasy podstawowej dodaje obsługi polecenia tylko wtedy, gdy program obsługi nie jest już zarejestrowany.Dzięki temu klas pochodnych zastąpić obsługę każdego polecenia.Klas pochodnych należy dodać polecenia, zanim będą wywoływać klasy podstawowej.
Przykłady
W tym przykładzie dodaje niestandardowe polecenie do menu skrótów.Gdy użytkownik tworzy roztwór w projektancie generowanych i kliknie prawym przyciskiem myszy diagram jednego dodatkowe polecenia, Przykładowe polecenie, pojawia się w menu skrótów.
Następujący wiersz w pliku Commands.vsct pojawi się po instrukcji include.
#define cmdidMyMenuSample 0x0008
Następujący wiersz w pliku Commands.vsct pojawi się po GENERATED_BUTTONS.
guidCmdSet:cmdidMyMenuSampe, guidCommonModelingMenu:grpidExplorerMenuGroup, 0x8020, OI_NOID, BUTTON, DIS_DEF, "&Sample Command";
W folderze VsctComponents następującego pliku cs jest dostępny.Obszar nazw i niektórych metod ma nazwę projektu, MenuSample, w nich.
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);
}
}
Zabezpieczenia programu .NET Framework
- Pełne zaufanie do bezpośredniego wywołującego. Tego elementu członkowskiego nie można używać w kodzie częściowo zaufanym. Aby uzyskać więcej informacji, zobacz Używanie bibliotek pochodzących z częściowo zaufanego kodu.