将子菜单添加到 Visual Studio 项目项节点 [英] Adding SubMenu to Visual Studio Project Item Node
问题描述
如何在 Visual Studio 解决方案资源管理器中右键单击文件项时添加菜单和子菜单项?
How can I add a menu and sub menu items when right click on a file item visual studio solution explorer?
我有一个菜单和三个子菜单项,当我在解决方案资源管理器中右键单击一个文件时将显示这些菜单项,如下图所示.
I have one menu and three sub menu items which will be displayed when I right click on a file in solution explorer like the below picture.
我尝试使用 .vsct 按钮,但它会显示在上下文菜单上,我无法添加子菜单
I tried using .vsct buttons but it will display on context menu and Iam unable to add sub menus
推荐答案
编写 VSCT
文件有些棘手;您需要的是菜单和按钮的组合.首先,您需要在 VSCT 文件中引用 IDM_VS_CTXT_ITEMNODE
组.
Authoring VSCT
files is somewhat tricky; what you´ll need is a combination of a menu and buttons. First of all you need to reference the IDM_VS_CTXT_ITEMNODE
group in your VSCT file.
<Group guid="guidCmdSet" id="grpIdMenuProjectItem" priority="0x0800">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
</Group>
然后创建一个新菜单并将其添加到该组...
Than you create a new menu and add it to that group...
<Menu guid="guidCmdSet" id="sampleMenu" type="Menu" priority="0x1000">
<Parent guid="guidCmdSet" id="grpIdMenuProjectItem" />
<CommandFlag>IconAndText</CommandFlag>
<Strings>
<ButtonText>Sample Menu</ButtonText>
<CommandName>Sample Menu</CommandName>
</Strings>
</Menu>
对于子菜单项,需要另一个组,该组将添加到菜单中...
For the submenu items another group is required, which will be added to the menu...
<Group guid="guidCmdSet" id="sampleMenuGroup" priority="0x1000">
<Parent guid="guidCmdSet" id="sampleMenu"/>
</Group>
至少您使用按钮定义子菜单项并将它们添加到子菜单组...
At least you define your submenu items using buttons and add them to the submenu group...
<Button guid="guidCmdSet" id="sampleMenuItem" priority="0x1000" type="Button">
<Parent guid="guidCmdSet" id="sampleMenuGroup"/>
<CommandFlag>TextOnly</CommandFlag>
<Strings>
<ButtonText>Sample Menu Item 1</ButtonText>
<CommandName>sampleMenuItem1</CommandName>
</Strings>
</Button>
不要忘记定义所有符号,否则资源将无法编译.
Don´t forget to define all symbols, otherwise the resource won´t compile.
<IDSymbol name="grpIdMenuProjectItem" value="0x1020"/>
<IDSymbol name="sampleMenu" value="0x1021"/>
<IDSymbol name="sampleMenuGroup" value="0x1022"/>
<IDSymbol name="sampleMenuItem" value="0x1023"/>
这就是你得到的......
And this is what you get...
这篇关于将子菜单添加到 Visual Studio 项目项节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!