Select to view content in your preferred language

Context menu in ArcGIS 10 add-in

2848
3
08-24-2010 03:08 PM
LesleyBross
Deactivated User
Has anyone found a sample for wiring up a context menu in an ArcGIS 10 add-in? There are samples for the .NET framework but these refer to GUIDs which you don't have with an add-in. The xml configuration file doesn't appear to generate a class that you can grab with ThisAddIn.ids... Thank you.
0 Kudos
3 Replies
LesleyBross
Deactivated User
I was able to pop a context menu this morning with the following code. This is called from a button on a dockable window. Hope it helps someone...

    Private Sub btnContext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnContext.Click
        Dim contextMenuID As UID = New UIDClass()
        ' id property of menu from Config.esriaddinx document
        contextMenuID.Value = "Dharma_Inst_CustomUIElements_Context_Menu"
        Dim document As ESRI.ArcGIS.Framework.IDocument = My.ArcMap.Document
        Dim menu As ESRI.ArcGIS.Framework.ICommandBar = TryCast(document.CommandBars.Find(contextMenuID, False, False), ESRI.ArcGIS.Framework.ICommandBar)
        ' pop context menu at mouse position
        menu.Popup(0, 0)
    End Sub
TimWhiteaker
Frequent Contributor
Thanks for the code.  I was able to successfully show my context menu on right click using your code.  However, after my command is finished executing, the normal context menu for maps (Full Extent, Fixed Zoom In, ...) appears.  How do I tell ArcMap that I have handled the right-click event?
0 Kudos
TimWhiteaker
Frequent Contributor
I found when I pop up the menu in the OnMouseDown handler (instead of OnMouseUp), then only my custom context menu appears.  This achieves my desired result of preventing the normal context menu from appearing after my code has executed.
0 Kudos