I have a UICommand in my add-in which displays the form and all that works great. What I want to add to do is add a button to that form which is used to click on the map, get x,y coordinates, and then populate them back into a textbox on the windows form
Dim theForm As frmPhotoDlg 'My custom form's class name theForm = System.Windows.Forms.Application.OpenForms(0) theForm.txtLatitude.Text = pPoint.Y theForm.txtLongitude.Text = pPoint.X
Dim theForm As frmPhotoDlg 'My custom form's class name theForm = System.Windows.Forms.Application.OpenForms(0)
Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs) MyBase.OnMouseDown(arg) Dim application As ESRI.ArcGIS.Framework.IApplication Dim pMxDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument Dim pPoint As ESRI.ArcGIS.Geometry.IPoint Dim pClone As ESRI.ArcGIS.esriSystem.IClone Dim pGeometry As ESRI.ArcGIS.Geometry.IGeometry Dim pSpatialRefFactory As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory Dim pSpatialRef As ESRI.ArcGIS.Geometry.ISpatialReference Dim pGeographicCoordSys As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem Dim pProjectedCoordSys As ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem Dim theForm As frmPhotoDlg Dim theResults As String Try 'Get the point where the user clicked application = My.ArcMap.Application Dim document As ESRI.ArcGIS.Framework.IDocument = application.Document pMxDoc = CType(document, ESRI.ArcGIS.ArcMapUI.IMxDocument) If pMxDoc.CurrentLocation.IsEmpty Then Exit Sub 'Clone the point because we don't want to alter 'the actual document's current location point pClone = pMxDoc.CurrentLocation pPoint = pClone.Clone pGeometry = pPoint 'Create a new geographic coordinate system to use in the conversion pSpatialRefFactory = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment pGeographicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_NAD1983) pSpatialRef = pGeographicCoordSys 'QI pSpatialRef.SetFalseOriginAndUnits(-180, -90, 1000000) pGeometry.Project(pSpatialRef) Dim theDegrees As Double Dim theMinutes As Double Dim theSeconds As Double Dim longDms As String Dim latDms As String Dim longDD As Double Dim latDD As Double longDD = Math.Abs(pPoint.X) latDD = pPoint.Y theDegrees = Int(longDD) theMinutes = (longDD - theDegrees) * 60 theSeconds = Int((theMinutes - Int(theMinutes)) * 60) longDms = theDegrees & "° " & Int(theMinutes) & "' " & theSeconds & Chr(34) theDegrees = Int(latDD) theMinutes = (latDD - theDegrees) * 60 theSeconds = Int((theMinutes - Int(theMinutes)) * 60) latDms = theDegrees & "° " & Int(theMinutes) & "' " & theSeconds & Chr(34) theResults = "DECIMAL DEGREES:" & vbNewLine & vbNewLine & vbTab & "Latitude: " & pPoint.Y & vbNewLine theResults = theResults & vbTab & "Longitude: " & pPoint.X & vbNewLine & vbNewLine & "DEGREES/MINUTES/SECONDS:" theResults = theResults & vbNewLine & vbNewLine & vbTab & "Latitude: " & latDms & vbNewLine & vbTab & "Longitude: " & longDms 'My.Computer.Clipboard.SetText(theResults) theForm = System.Windows.Forms.Application.OpenForms(0) theForm.txtLatitude.Text = pPoint.Y theForm.txtLongitude.Text = pPoint.X 'MsgBox(theResults, vbInformation, "Geographic Results") pSpatialRefFactory = Nothing pGeographicCoordSys = Nothing pProjectedCoordSys = Nothing pSpatialRef = Nothing pClone = Nothing pPoint = Nothing pGeometry = Nothing pMxDoc = Nothing application = Nothing document = Nothing Catch ex As Exception globalErrorHandler(ex) End Try End Sub
I'm still a bit green with VB.NET...