using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.Geometry; //For geometry IPoint
using ESRI.ArcGIS.Carto; //For ActiveView
using ESRI.ArcGIS.Display; //For IScreenDisplay
namespace myProject
{
public class GetCoord: ESRI.ArcGIS.Desktop.AddIns.Tool
{
public GetCoord()
{
}
protected override void OnUpdate()
{
}
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
{
try
{
//Get the active view
IActiveView activeView = ArcMap.Document.ActiveView;
IScreenDisplay screenDisplay = activeView.ScreenDisplay;
//Get the point when the user clicks on the map
IPoint myPoint = screenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
System.Windows.Forms.MessageBox.Show("X coordinate from the IPoint: " + myPoint.X);
System.Windows.Forms.MessageBox.Show("Y coordinate fom the IPoint: " + myPoint.Y);
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show("Problem to get the coordinates: " + e.Message);
}
}
}
}
public override IPoint OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
{
//Get the active view
IActiveView activeView = ArcMap.Document.ActiveView;
IScreenDisplay screenDisplay = activeView.ScreenDisplay;
//Get the point when the user clicks on the map
IPoint myPoint = screenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
return myPoint;
}
Ipoint myNewPoint = GetCoord.OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg);
I have a form with a button on it. The button's click event activates a tool which in turn gets the a point object. My question is how can the form get the point from the tool so that the x and y values can be used in the form?
Robert
Public Class DrawTool Inherits ESRI.ArcGIS.Desktop.AddIns.Tool 'Public LineType As String Private m_LineFeedback As ESRI.ArcGIS.Display.INewBezierCurveFeedback = Nothing Private graphicsContainer As ESRI.ArcGIS.Carto.IGraphicsContainer Public Sub New() End Sub Protected Overrides Sub OnUpdate() End Sub Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs) MyBase.OnMouseDown(arg) 'etc
Private Sub Draw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPoint.Click, btnLocation.Click, btnPolygon.Click, btnFreehand.Click, btnRectangle.Click Dim pUID As New ESRI.ArcGIS.esriSystem.UID Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem pUID.Value = My.ThisAddIn.IDs.DrawTool pCommandItem = m_application.Document.CommandBars.Find(pUID, False, False) Select Case sender.name Case "btnPoint" 'code to do some things for the Point tool Case "btnLocation" 'code to do some things for the Location tool 'etc End Select m_application.CurrentTool = pCommandItem