locked
How to Add context menu to shapes RRS feed

  • Question

  • I am trying to add a context menu to a shape. What I did so far was:

    1) Added a "public override void OnMouseUp" method do Shapes.cs
    2) Instantiated a context menu
    3) Tried to bind the context menu to the GeometryShape and show it, but it requires a Control and I'm stuck, since the GeometryShape class is not a Control.

    Any suggestions?

    Thanks,
    -- AFurtado
    Tuesday, April 19, 2005 7:24 AM

Answers

  • Hi AFurtado,

    There are two routes here.
    Currently it sounds like you are using Windows Forms context menus.  You can probably get this route to work, but it is not going to integrate smoothly with Visual Studio's other menus and so we wouldn't recommend it.
    You can get the control from a Shape by Querying your Package for the IMonitorSelectionService service, which has a CurrentDocView member.  Your DocView class has a public VSDiagramView-typed CurrentDesigner method which is your Control.

    However, to get a fully integrated addition to your context menu, a better approach is to follow the standard VSIP method for adding a context menu by adding a new Command into the IDG_ContextGroup.
    You can find instructions on adding a context menu in a CTC file in the VSIP documentation under the heading, "How to: Create Context Menus".
    You'll need to add your new command id to PkgCmdId.h and to PkgCmdId.cs and add your command handler to the implementation of GetMenuCommands() in CommandSet.cs

    I hope this points you in the right direction.
    Gareth
    Tuesday, April 19, 2005 6:30 PM
  • Juergen,

     

    The postings above relate specifically to adding menus to graphical objects on a design surface hosted inside Visual Studio, so won't have any bearing on Excel.

     

    Have at look at this link for a list of newsgroups and resources related specifically to Office development: http://msdn2.microsoft.com/en-us/office/aa905346.aspx. The Excel development newsgroup might be your best bet: http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.excel.programming.

     

    Regards,

    Duncan

     

     

    • Marked as answer by Blair McG Wednesday, June 11, 2008 10:46 AM
    Saturday, June 2, 2007 10:16 AM

All replies

  • Hi AFurtado,

    There are two routes here.
    Currently it sounds like you are using Windows Forms context menus.  You can probably get this route to work, but it is not going to integrate smoothly with Visual Studio's other menus and so we wouldn't recommend it.
    You can get the control from a Shape by Querying your Package for the IMonitorSelectionService service, which has a CurrentDocView member.  Your DocView class has a public VSDiagramView-typed CurrentDesigner method which is your Control.

    However, to get a fully integrated addition to your context menu, a better approach is to follow the standard VSIP method for adding a context menu by adding a new Command into the IDG_ContextGroup.
    You can find instructions on adding a context menu in a CTC file in the VSIP documentation under the heading, "How to: Create Context Menus".
    You'll need to add your new command id to PkgCmdId.h and to PkgCmdId.cs and add your command handler to the implementation of GetMenuCommands() in CommandSet.cs

    I hope this points you in the right direction.
    Gareth
    Tuesday, April 19, 2005 6:30 PM
  • Hello,

     

    Your article ist interesting and related to my problem.

     

    During the porting of some VBA code to Excel 2007, I had to port user defined context menus for Graphical shapes. The code works fine under Excel 97 to Excel 2003, but under Excel 2007 the access to user context menus does not work that way.

     

    Is there an example on how to add user defined context menus for shapes by the help of vba code under Excel 2007 ?

     

    Thank you

     

    Juergen

    Friday, June 1, 2007 10:55 AM
  • Juergen,

     

    The postings above relate specifically to adding menus to graphical objects on a design surface hosted inside Visual Studio, so won't have any bearing on Excel.

     

    Have at look at this link for a list of newsgroups and resources related specifically to Office development: http://msdn2.microsoft.com/en-us/office/aa905346.aspx. The Excel development newsgroup might be your best bet: http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.excel.programming.

     

    Regards,

    Duncan

     

     

    • Marked as answer by Blair McG Wednesday, June 11, 2008 10:46 AM
    Saturday, June 2, 2007 10:16 AM
  • Just documenting here that the link below presents a nice explanation on how to add context menus:

    http://stalamoni.blogspot.com/2007/12/adding-menu-to-dsl-using-vsnet-2008-sdk.html

     

    BR,

    -- AFurtado

    Friday, May 23, 2008 3:00 AM