3

I am developing an add-in for ArcMap 10.0 where I need to execute code when there is a click on the map open. How do I do this? I am using VB in Visual Studio 2010. I also need to get the coordinates from the click event.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 30, 2012 at 21:17

1 Answer 1

2

If you have created an add-in and added a ESRI.ArcGIS.Desktop.AddIns.Tool to it then stub out the following event:

Protected Overrides Sub OnMouseDown(ByVal arg As
 ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
' --write your function here--
End Sub

arg.X and arg.Y will be the coordinates where the user clicked.

You will most likely want to convert the x and y values to the transformation used by the display:

Dim mxDoc As IMxDocument = CType(My.ArcMap.Application.Document, IMxDocument) 
Dim clickedPoint As ESRI.ArcGIS.Geometry.IPoint =
 mxDoc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y)
Michael Todd
1,9764 gold badges20 silver badges32 bronze badges
answered Apr 30, 2012 at 21:46
5
  • I had this code already, but it says ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs is not accessible because it is protected. How can I fix this? Commented Apr 30, 2012 at 21:50
  • code Public Class toolIdentify Inherits ESRI.ArcGIS.Desktop.AddIns.Tool Public Sub New() End Sub Protected Sub OnClick() End Sub Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs) End Sub Protected Overrides Sub OnUpdate() End Sub End Class code Did you put it in the ITool class itself? Commented Apr 30, 2012 at 21:59
  • I'm only using a button currently, because I don't need it to be in a specific tool. Should I do this with a tool? Or is a button fine? Commented Apr 30, 2012 at 22:04
  • Ok, I may have misread your question or you may need to clarify. If you need something to happen when user opens a map document using the open button then your addin needs an event handler (IDocumentEvents_Event interface). If you want to capture a mouse click on the map then you need an ITool as I described. Commented Apr 30, 2012 at 22:09
  • Thank you! I figured out that I was being dumb, I thought the button had to be on a tool but I just needed the tool. Also, Michael I saw your edit about the transformation. Is that to get the actual latitude and longitude? I'm trying to get latitude and longitude in decimal degrees as individual variables. I am currently trying that code but it says "Type 'IPoint' is not defined". How do I make it work? Clearly I'm new to this add-in programming, so I appreciate all the help. Commented May 1, 2012 at 2:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.