Activate Tool from Docked Window

1260
4
05-21-2017 11:42 AM
AlexanderMogren
New Contributor

Hey everybody.

I have a little question. I know that what I want to do this can be done with just adding a Tool Add-in but I want to do this from my Docked window.

I have a checkbox and when it is checked I override the OnMouseDown for the docked window but I want to listen to the OnMouseDown in the IMxDocument.

Here is my code so far:

   protected override void OnMouseDown(MouseEventArgs e)
   {
      base.OnMouseDown(e);
      if (mapLocation.Checked)
      {
         System.Windows.Forms.Cursor.Current = Cursors.Arrow;
         IMxDocument mDoc = ArcMap.Application.Document as IMxDocument;
         IPoint mPoint;
         mPoint = mDoc.CurrentLocation;
         double lng, lat;
         lng = mPoint.X;
         lat = mPoint.Y;
         MessageBox.Show(lng+", "+lat,"Retrived Map Data");
}
}

So I would like this code to fire when I pressing in the Data View and not in the Dockable Window as it does now.

Thankful for answers.

0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor

I'm not sure what you are asking is possible. The OnMouseDown event is something that is fired off from a tool when you click on the map, so a tool needs to be active to fire the event.

I did something similar in the past, I had a standard button on a docked window; when clicked on it got a handle on an addin tool and then added an event handler to it called grabID. The addin tool raised the event grabID in the OnMouseDown event of the tool. I also added to the tool a public function that would return the XY of the point clicked at in the OnMouseDown event. The dockable window was listening out for the grabID event and then read the XY from the public function.  This was my method for capturing tool clicks on maps by the docked window.

0 Kudos
AlexanderMogren
New Contributor

Hey. I solved it by doing this:

ICommandItem deepARCTool = ArcMap.Application.Document.CommandBars.Find("deepARC_GDLM_Root");
ArcMap.Application.CurrentTool = deepARCTool;

But I have another problem. I am using this to also open a dockable window. So how can I toggle the dockable window as when using a button?

Now I press my tool in the toolbar and my dockable window opens. If I close the dockable windows and press the tool again in the toolbar the dockable windows wont open. Must I set the dockable windows to null or how is this made?

0 Kudos
DuncanHornby
MVP Notable Contributor

For the record there is a thread over on GIS SE that is similar.

0 Kudos
AlexanderMogren
New Contributor

Ok didnt know that. You dont know how to fix existing featureclass data that now shows in the data view.

0 Kudos