I am new to programming in C#.net.
I have a very simple desktop application in ArcMap. I'm trying to get the coordinates when a user clicks a button on a toolbar and when click the map. The toolbar is implemented using the BaseToolBar. I use the base tool to grab the mouse down event ( Not sure whether this is the correct way even) Here is the code which it generates.
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;
using System.Windows.Forms;
namespace GIS_FORMS
{
/// <summary>
/// Summary description for GetXY.
/// </summary>
[Guid("b1e4d6f0-53de-44d3-b679-f29432d1fe35")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("GIS_FORMS.GetXY")]
public sealed class GetXY : BaseTool
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Unregister(regKey);
}
#endregion
#endregion
private IApplication m_application;
public GetXY()
{
//
// TODO: Define values for the public properties
//
base.m_category = "GIS_FORMS"; //localizable text
base.m_caption = "get xy"; //localizable text
base.m_message = "get xy"; //localizable text
base.m_toolTip = "get xy"; //localizable text
base.m_name = "get_xy"; //unique id, non-localizable (e.g. "MyCategory_ArcMapTool")
try
{
//
// TODO: change resource name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
#region Overriden Class Methods
/// <summary>
/// Occurs when this tool is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
m_application = hook as IApplication;
//Disable if it is not ArcMap
if (hook is IMxApplication)
base.m_enabled = true;
else
base.m_enabled = false;
// TODO: Add other initialization code
}
/// <summary>
/// Occurs when this tool is clicked
/// </summary>
public override void OnClick()
{
// TODO: Add GetXY.OnClick implementation
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
// TODO: Add GetXY.OnMouseDown implementation
MessageBox.Show("X position is " + X.ToString() +"Y position is :" + Y.ToString());
}
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
// TODO: Add GetXY.OnMouseMove implementation
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
// TODO: Add GetXY.OnMouseUp implementation
}
#endregion
}
}
Now I need to get the coordinates out.
To do this where should I call the event mouse down event?
The message box does not display at all.