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.

1 Answer 1


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

' --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)
  • 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?
    – Xoph
    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? 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?
    – Xoph
    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. 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.
    – Xoph
    May 1, 2012 at 2:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.