protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { int intx = arg.X; int inty = arg.Y; IPoint pPoints = new PointClass(); pPoints.PutCoords(intx, inty); IActiveView activeView = ArcMap.Document.ActiveView; pPoints = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(-100, 40);//x,y为屏幕坐标 ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay; ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation; pPoints = displayTransformation.ToMapPoint(-120, 40); IMxDocument doc = ArcMap.Document; IMap map = doc.FocusMap; pPoints = doc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(-100, 40); AlterForm frm = null; if (frm == null || frm.IsDisposed) { frm = new AlterForm(intx, inty); } frm.Show(); frm.TopMost = true; frm.Width = 400; frm.Height = 300; frm.Left = 500; }
/// <summary> /// Gets the number of map units for a given number of pixels /// </summary> /// <param name="pixelUnits">number of pixels to convert</param> /// <returns>double</returns> /// <remarks>Converted from http://resources.esri.com/help/9.3/ArcGISDesktop/com/samples/Cartography/Display/dc78c617-adbb-4145-bc9a-530230905f80.htm</remarks> public double ConvertPixelsToMapUnits(double pixelUnits) { double realWorldDisplayExtent = 0; long pixelExtent = 0; double sizeOfOnePixel = 0; ESRI.ArcGIS.Display.IDisplayTransformation pDT = null; tagRECT deviceRECT; ESRI.ArcGIS.Geometry.IEnvelope pEnv = null; ESRI.ArcGIS.Carto.IActiveView pActiveView = null; // Get the width of the display extents in Pixels // and get the extent of the displayed data // work out the size of one pixel and then return // the pixels units passed in mulitplied by that value pActiveView = this.ActiveView; // Get IDisplayTransformation pDT = pActiveView.ScreenDisplay.DisplayTransformation; // Get the device frame which will give us the number of pixels in the X direction deviceRECT = pDT.get_DeviceFrame(); pixelExtent = deviceRECT.right - deviceRECT.left; // Now get the map extent of the currently visible area pEnv = pDT.VisibleBounds; // Calculate the size of one pixel realWorldDisplayExtent = pEnv.Width; sizeOfOnePixel = realWorldDisplayExtent / pixelExtent; //Multiply this by the input argument to get the result return(pixelUnits * sizeOfOnePixel); }