c# - 如何使用 VSPackage 在 Visual Studio 2012 中添加多个菜单项?

标签 c# visual-studio-2012 sdk

我研究过这个link为了在 Visual Studio 2012 中使用 VSPackage 添加自定义菜单命令。

一切都很好,直到我想添加多个菜单项。

在提供的文档中,他们没有解释如何再添加一个菜单项。

例如,我在TfsUtility.vsct文件中做了如下设置:

<Menus>
    <Menu guid="guidTfsUtilityCmdSet" id="TfsUtility" priority="0x700" type="Menu">
        <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_TOOLSADDINS" />
        <Strings>
            <ButtonText>Tfs Utility</ButtonText>
            <CommandName>Tfs Utility</CommandName>
        </Strings>
    </Menu>
</Menus>

...

<Group guid="guidTfsUtilityCmdSet" id="MyMenuGroup" priority="0x0600">
    <Parent guid="guidTfsUtilityCmdSet" id="TfsUtility"/>
</Group>

...

<Button guid="guidTfsUtilityCmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">
    <Parent guid="guidTfsUtilityCmdSet" id="MyMenuGroup" />
    <Strings>
        <ButtonText>Branch</ButtonText>
    </Strings>
</Button>

...

<GuidSymbol name="guidTfsUtilityCmdSet" value="{d5549d5d-47af-40e0-a7e5-e9ed7f64d577}">

    <IDSymbol name="MyMenuGroup" value="0x1020" />
    <IDSymbol name="cmdidMyCommand" value="0x0100" />

    <IDSymbol name="TfsUtility" value="0x1021"/>
</GuidSymbol>

问题:

  1. 如何在菜单选项中添加更多选项(例如在分支之后)? enter image description here

  2. 如何为每个菜单项关联命令?我想为每个菜单项显示不同的消息。

非常感谢

最佳答案

  1. 要再添加一个菜单项,请再添加一个具有不同 ID 的 Button 部分。

  2. 要执行命令,您需要提供 MenuItemCallback 并将其注册到 OleMenuCommandService:

OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

if ( null != mcs )
{
   // Create the command for the menu item.
   CommandID menuCommandID = new CommandID(guidCommandGroup, myCommandID);
   MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID );
   mcs.AddCommand( menuItem );
}

参见 Command Implementation获取更多信息。

关于c# - 如何使用 VSPackage 在 Visual Studio 2012 中添加多个菜单项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21122889/

相关文章:

android - Eclipse + Android SDK,不会获取、更新、连接或做任何有用的事情

android - 在自定义 Android(或 PhoneGap)应用程序中嵌入 Adob​​e Reader

visual-studio-2012 - 如何在Visual Studio中使用PhoneGap

c# - 在一个 View 中渲染多个强类型分部 View ?

c# - 如何使用 SharpKml 创建 StyleMap 标签?

c# - 将 "ä"编码为 "%E4"

asp.net-mvc - 将我的 asp.net mvc 发布到 IIS 生产服务器。我应该使用 Visual Studio 来执行此操作吗

android - Delphi Rio 无法读取设置了 READ_EXTERNAL_STORAGE 权限的外部存储

c# - 为什么派生自 ControllerBase 与 Controller for ASP.NET Core Web API?

c# - Windows 应用商店应用程序数据将 TextBlock 绑定(bind)到来自 Web 服务的对象