There is nothing wrong with your code. It works fine. You are doing it right. I can select the tool, click on the map and the coordinates are displayed in the message box.
To convert to map units add references to ESRI.ArcGIS.Display, ESRI.ArcGIS.Geometry and ESRI.ArcGIS.Carto
and replace the OnMouseDown with this
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = (m_application.Document as IMxDocument).ActiveView.ScreenDisplay;
ESRI.ArcGIS.Geometry.IPoint point = screenDisplay.DisplayTransformation.ToMapPoint(X, Y);
MessageBox.Show("X position is " + point.X.ToString() + "Y position is :" + point.Y.ToString());
}
Edit: You don't "call the mouse down event". The code you place in the OnMouseDown function is executed when the map is clicked. OnMouseDown is an event handler.
It's possible to make it work with ArcMap 10.0, but it's not easy and deployment-friendly
First, in your visual studio project, set your target framework to .NET Framework 3.5.
Then, edit the Config.esriaddinx file and modify the "Targets" section to add compatibility with ArcGIS Desktop 10.0, like this:
<Targets>
<Target name="Desktop" version="10.0" />
<Target name="Desktop" version="10.1" />
</Targets>
Finally, as described in an older post, you have to alter the ArcMap.exe.config by adding the following line inside each "dependentAssembly" block
<bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
Once modified, it should look like this
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ESRI.ArcGIS.ADF" culture="" publicKeyToken="8fc3cc631e44ad86"/>
<bindingRedirect oldVersion="9.3.0.0-9.3.2.0" newVersion="10.0.0.0"/>
<bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
I came to the conclusion that even if it's possible, I'm better off compiling with the lowest version of ArcMap I'm willing to support.
EDIT: See also Rich Wawrzonek's post for an alternative (not recommended by ESRI)
EDIT2: According to Esri, the best way is set up a virtual machine with 10.0 installed on it (see this post)
Best Answer
If you have created an add-in and added a ESRI.ArcGIS.Desktop.AddIns.Tool to it then stub out the following event:
arg.X
andarg.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: