locked
How to add custom menu item to WinForm designer context menu RRS feed

  • Question

  • Hello all

    I've created VSPackage project. Now i want custumize context menu. Does anyone knows how to add custom menu item to WinForms designer context menu?

    I would be very much obliged for any example or advice. Thanks

    Wednesday, June 30, 2010 8:32 AM

Answers

  • Thank you for answer Chao, i have experimented with component designer and found another way how to achieve this in runtime:

    IDesignerHost designerHost = (IDesignerHost)(Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2).ActiveDocument.ActiveWindow.Object;
    IDesigner designer = designerHost.GetDesigner(designerHost.RootComponent);
    designer.Verbs.Add(new DesignerVerb("Custom item", new EventHandler(CustomItem_Click)));

    But there are only one limitation - custom menu item will be added only for one type (its type of designerHost.RootComponent in our case).

    Also this custom item will be added to the component SmartTags and bottom area of the properties window.

    • Marked as answer by Boris Lapaev Friday, July 2, 2010 6:38 PM
    Friday, July 2, 2010 6:33 PM

All replies

  • Hello, neverMind

    As far as I invested(I have researched this for hours), this may be not achievable.

    We need to get a menu item in the winform designer context menu, and find the group of it menu group (we need two tools to achieve this VSCTPowerToy and VSSDKAssist). But the designer conext menu group is GUID:{83285929-227c-11d3-b870-00c04f79f802},ID: 0x0. I failed to add our custom menu as a son of the context menu group.

    But I managed to add a menu to View menustrip. See the following

          <Group guid="guidVSIPViewDesignerCmdSet" id="MyMenuGroup" priority="0x0600">

            <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_VIEW"/>

          </Group>

    <!--This is View menu group-->

        <GuidSymbol name="guidSHLMainMenu" value="{d309f791-903f-11d0-9efc-00a0c911004f}">

          <IDSymbol name="IDM_VS_MENU_VIEW" value="0x82" />

    </GuidSymbol>

    And we could also add the menu to, the menustrip that appears when you right click your form node in your solution explorer.

        <GuidSymbol name="guidSHLMainMenu" value="{d309f791-903f-11d0-9efc-00a0c911004f}">

          <IDSymbol name="IDM_VS_CTXT_ITEMNODE" value="0x430" />

    </GuidSymbol>

     

          <Group guid="guidVSIPViewDesignerCmdSet" id="MyMenuGroup" priority="0x0600">

            <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE"/>

          </Group>

    Here is the two links about the use of VSCTPowerToy and VSSDKAssist.

    http://code.msdn.microsoft.com/VSCTPowerToy

    http://blogs.msdn.com/b/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx

    For the VSCT that integrate menu items to IDE, Please reference this link

    http://msdn.microsoft.com/en-us/library/bb166366.aspx

    Thanks

    Chao

    Friday, July 2, 2010 1:00 PM
  • Thank you for answer Chao, i have experimented with component designer and found another way how to achieve this in runtime:

    IDesignerHost designerHost = (IDesignerHost)(Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2).ActiveDocument.ActiveWindow.Object;
    IDesigner designer = designerHost.GetDesigner(designerHost.RootComponent);
    designer.Verbs.Add(new DesignerVerb("Custom item", new EventHandler(CustomItem_Click)));

    But there are only one limitation - custom menu item will be added only for one type (its type of designerHost.RootComponent in our case).

    Also this custom item will be added to the component SmartTags and bottom area of the properties window.

    • Marked as answer by Boris Lapaev Friday, July 2, 2010 6:38 PM
    Friday, July 2, 2010 6:33 PM