Pimplebutt

Activate a command (or tool) by using a .NET context menu

Discussion created by Pimplebutt on Jun 15, 2011
Latest reply on Jun 16, 2011 by Pimplebutt
My environment:

  • Visual Studio 2008

  • VB.NET

  • ArcEngine 9.3.1

  • File Geodatabase

I have a .NET Context Menu (right-click) that I have various commands on that have nothing to do with ESRI or any of ArcObjects.  Just your ordinary vanilla .NET context menu.

I would like to add to this .NET Context Menu, a ToolStripMenuItem that activates an ESRI command (or tool?).

Normally that ESRI command (or tool) would be placed on an ESRI toolbar as a button.
The ESRI command (or tool) I am interested in using has not been placed on any of my ESRI toolbars, nor do I want to. 

I don't care about showing the official ESRI icon for the command or anything, I just want to make the command (or tool) active when I click on the MenuItem on my .NET Context Menu.

Can you point me to how to do this?

Based on another post, I have gotten this far...

Friend Sub BuildMapContextMenu()
 _mapControlContextMenu.Items.Clear()

 Dim inkToolMenuItem As ToolStripMenuItem = New ToolStripMenuItem("Highlight Tool", Nothing, AddressOf CallInkTool)

 _mapControlContextMenu.Items.Insert(0, inkToolMenuItem)
End Sub

Friend Sub CallInkTool(ByVal sender As Object, ByVal e As System.EventArgs)

 Dim cmd_ As ICommand = New ControlsInkHighlightTool
 cmd_.OnCreate(Me.MapControl.Object)
 cmd_.OnClick()

End Sub


The problem with this code though is that to tool only appears for a fraction of a second after I click the menu item.  I have to click the menu item, and then immediately begin highlighting in order to get it to work.  The tool won't remain active between highlights either.  As soon as I complete one, it goes back to regular arrow cursor and I have to click the menu item again and immediately begin highlighting.

Thanks a lot for any help.

Outcomes