I'm trying to convert some old VB code into C#, and unsure of how to proceed with code that does that task mentioned in the subject. Below is the old vb code. My problem being that I do not know the modern .net sdk equivalents for the calls in C#. It seems like it should be pretty simple to get the view extent and calculate the center, but apparently, it's a bit more involved then I expected. 🙂
Try 'TRY TO GET THE CENTER SCREEN LOCATION FROM THE ACTIVE VIEW, JUST SHOW THE FORM ON ERROR
Dim pPoint As ESRI.ArcGIS.Geometry.IPoint
pPoint = New ESRI.ArcGIS.Geometry.Point
pPoint.X = (m_pArcMapAV.Extent.XMax - m_pArcMapAV.Extent.XMin) / 2 + m_pArcMapAV.Extent.XMin
pPoint.Y = (m_pArcMapAV.Extent.YMax - m_pArcMapAV.Extent.YMin) / 2 + m_pArcMapAV.Extent.YMin
Dim pGeoCoordSystem As ESRI.ArcGIS.Geometry.ISpatialReference
Dim pProjCoordSystem As ESRI.ArcGIS.Geometry.ISpatialReference
Dim pGeoTrans As ESRI.ArcGIS.Geometry.IGeoTransformation
Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory
pSpatRefFact = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment
pGeoCoordSystem = pSpatRefFact.CreateGeographicCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984)
pProjCoordSystem = pSpatRefFact.CreateProjectedCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_NAD1983SPCS_AK3FT)
pGeoTrans = pSpatRefFact.CreateGeoTransformation(ESRI.ArcGIS.Geometry.esriSRGeoTransformationType.esriSRGeoTransformation_NAD1983_To_WGS1984_2)
Dim pGeo As ESRI.ArcGIS.Geometry.IGeometry2
pGeo = pPoint
pGeo.SpatialReference = pProjCoordSystem
pGeo.ProjectEx(pGeoCoordSystem, ESRI.ArcGIS.Geometry.esriTransformDirection.esriTransformForward, pGeoTrans, 0, 0, 0)
Me.tbxLat.Text = CStr(pPoint.Y)
Me.tbxLon.Text = CStr(pPoint.X)
Catch ex As Exception
'DO NOTHING
End TryAlso, lol at the code paste feature not having a vb option.