Repository navigation
How do I add a sub menu to the WinForms Designer right-click menu in Visual Studio 2022? #579
|
I'm developing a Visual Studio 2022 Community VSIX Project (Community Visual Studio Toolkit) targeting .NET Framework 4.8. Is there a way to do this ? |
Replies: 2 comments
|
The designer's right-click menus are regular command table menus, so you can parent your own group to them in your VSCommandTable.vsct. Right-clicking a control opens <Menus>
<Menu guid="MyPackage" id="MySubMenu" type="Menu" priority="0x0100">
<Parent guid="MyPackage" id="MyDesignerGroup" />
<Strings><ButtonText>My Tools</ButtonText></Strings>
</Menu>
</Menus>
<Groups>
<Group guid="MyPackage" id="MyDesignerGroup" priority="0x0600">
<Parent guid="guidWinformsMenuGroup" id="IDM_IF_CTXT_SELECTION" />
</Group>
<Group guid="MyPackage" id="MySubMenuGroup" priority="0x0100">
<Parent guid="MyPackage" id="MySubMenu" />
</Group>
</Groups>
<!-- your Buttons use <Parent guid="MyPackage" id="MySubMenuGroup" /> -->
<!-- after </Commands> -->
<CommandPlacements>
<CommandPlacement guid="MyPackage" id="MyDesignerGroup" priority="0x0600">
<Parent guid="guidWinformsMenuGroup" id="IDM_IF_CTXT_CONTAINER" />
</CommandPlacement>
</CommandPlacements>
<!-- in <Symbols> -->
<GuidSymbol name="guidWinformsMenuGroup" value="{74D21312-2AEE-11d1-8BFB-00A0C90F26F7}">
<IDSymbol name="IDM_IF_CTXT_SELECTION" value="0x0500" />
<IDSymbol name="IDM_IF_CTXT_CONTAINER" value="0x0501" />
</GuidSymbol>These are the menus of the in-process designer that .NET Framework projects use (the newest SDK copy of Menus.vsct calls them legacy), so check separately if you also design forms in .NET 6+ projects. |
|
@junkerderprovinz |
The designer's right-click menus are regular command table menus, so you can parent your own group to them in your VSCommandTable.vsct. Right-clicking a control opens
IDM_IF_CTXT_SELECTION(0x0500) and right-clicking the form itself opensIDM_IF_CTXT_CONTAINER(0x0501), both under the GUID{74D21312-2AEE-11d1-8BFB-00A0C90F26F7}; these matchMenuCommands.SelectionMenuandContainerMenuin the WinForms designer, and you can see the full definition intools/VSSDK/inc/Menus.vsctinside the Microsoft.VSSDK.BuildTools package. For the sub menu, add aMenuof typeMenuto your group, give it a group of its own and parent your buttons to that inner group (theCommandPlacementadds the same entry …