I'm working on an add-in for ArcMap 10.0 that adds a toolbar to ArcMap. One command (
OpenModelessDialogCommand) button on that toolbar opens a modeless WinForms dialog, from which a tool (
MyTool) can be activated in order to e.g. select a feature on the map.
Config.esriaddinx contains these command and toolbar declarations:
<Commands> <!-- this is the command that opens the modeless WinForms form, from where MyTool is available: --> <Button id="OpenModelessFormCommand" ... /> <!-- MyTool is not directly referenced in any toolbar defined in this file: --> <Tool id="MyTool" class="MyTool" ... /> </Commands> <Toolbars> <Toolbar ...> <Items> <Button refID="OpenModelessFormCommand" /> </Items> </Toolbar> </Toolbars>
What I'm having problems with is activating
MyTool in the form. All I've found on the internet is code samples along the lines of:
// get a reference to an instance of MyTool: ICommandItem myTool = ArcMap.Application.Document.CommandBars.Find("MyTool"); // activate MyTool: ArcMap.Application.CurrentTool = myTool;
However, this apparently requires that
MyTool actually appears in a command bar (e.g. toolbar) of my add-in. But that's not the case. So, I've tried this next:
ITool myTool = new MyTool(); ArcMap.Application.CurrentTool = myTool; // Type mismatch! An ICommandItem is expected.
I've even looked into adding an invisible
AxToolbarControl to my form and adding a button for
MyTool there; but then I'm running into problems on how to connect that toolbar (via
SetBuddyControl) to the opened document's map. I don't want the tool to function in a separate
AxMapControl, I want it to work directly with the main map shown in ArcMap.
How do I activate a custom tool that is not added to any toolbar (or other command bar, for that matter)?