CommandSet.GetMenuCommands Yöntem
Kısayol menüsündeki komutları görüntüler.
Ad alanı: Microsoft.VisualStudio.Modeling.Shell
Derleme: Microsoft.VisualStudio.Modeling.Sdk.Shell.11.0 (Microsoft.VisualStudio.Modeling.Sdk.Shell.11.0.dll içinde)
Sözdizimi
'Bildirim
Protected Overrides Function GetMenuCommands As IList(Of MenuCommand)
protected override IList<MenuCommand> GetMenuCommands()
Dönüş Değeri
Tür: System.Collections.Generic.IList<MenuCommand>
Menü komutları listesi.
Notlar
Bu yöntem geçersiz kılmak ve kendi komutlarınızı ekleyebilirsiniz.Kendi komutları eklemek için bunları özel .vsct dosyasında tanımlayın ve onları içinde özel .cs dosyasını arayın.
[!NOT]
Değişikliklerinizi CommandSet.cs dosyasına eklemeyin.Bu dosyayı yeniden oluşturulan Tasarımcısı oluşturmak her zaman oluşturulur.
Örnekler
Bu örnek, özel bir komut kısayol menüsüne ekler.Bir kullanıcı tarafından oluşturulan Tasarımcısı'nda bir çözüm oluşturur ve ek bir komut Diyagramı sağ tıklattığında doğrulama, kısayol menüsünde görünür.
Sonra Commands.vsct dosyasında aşağıdaki satırı görünür include deyimleri.
#define AssociationSortValidate 0x801
Commands.vsct dosyasında aşağıdaki satırı generated_buttons sonra görünür.
guidCmdSet:AssociationSortValidate, guidCmdSet:grpidContextMain, 0x0100, OI_NOID, BUTTON, DIS_DEF, "&Validate";
VsctComponents klasörü içinde aşağıdaki .cs dosyasının kullanılabilir.Ad ve yöntemlerden bazılarını projenin adı olan MenuSample, içlerindeki.
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 Güvenliği
- Anında arayanlar için tam güven. Bu üye kısmen güvenilen kodla kullanılamaz. Daha fazla bilgi için bkz. Kısmen güvenilen kod kitaplıklarını kullanma.