public void StartEditElement(IActiveView pView, ref IElement pElement) { if (pElement == null) { return; } m_pOrgElement = pElement; m_pBoundProp = (IBoundsProperties)m_pOrgElement; m_pTransform = (ITransform2D)m_pOrgElement; m_pActiveView = pView; m_pDisplay = pView.ScreenDisplay; m_pGraphicCtn = pView.GraphicsContainer; SetUI(m_pOrgElement); GetProperty(m_pDisplay, m_pOrgElement); //this.ShowDialog(); }
public bool HitTestSelectionElement(IActiveView pActiveView, long x, long y, bool bMapUnit) { try { if (pActiveView != null) { IGraphicsContainerSelect select = pActiveView as IGraphicsContainerSelect; if (select.ElementSelectionCount <= 0) { return(false); } IPoint point = null; if (bMapUnit) { point = new PointClass { X = x, Y = y }; } else { point = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint((int)x, (int)y); } IEnvelope bounds = new EnvelopeClass(); IBoundsProperties properties = null; IGeometry other = null; IRelationalOperator @operator = point as IRelationalOperator; IEnumElement selectedElements = null; selectedElements = select.SelectedElements; if (selectedElements == null) { return(false); } IElement element2 = null; selectedElements.Reset(); for (element2 = selectedElements.Next(); element2 != null; element2 = selectedElements.Next()) { if (!element2.Locked) { properties = element2 as IBoundsProperties; if (properties.FixedSize) { element2.QueryBounds(pActiveView.ScreenDisplay, bounds); } else { bounds = element2.Geometry.Envelope; } other = bounds; if (@operator.Within(other)) { return(true); } } } } return(false); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.ElementFun", "HitTestSelectionElement", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
private void AddPictureElement(string strFileName) { IPictureElement2 pictureElement = null; string suffix = strFileName.Substring(strFileName.Length - 3, 3).ToLower(); switch (suffix) { case "jpg": pictureElement = new JpgPictureElementClass(); break; case "gif": pictureElement = new GifPictureElementClass(); break; case "tif": pictureElement = new TifPictureElementClass(); break; case "emf": pictureElement = new EmfPictureElementClass(); break; case "bmp": pictureElement = new BmpPictureElementClass(); break; case "png": pictureElement = new PngPictureElementClass(); break; default: return; } try { pictureElement.ImportPictureFromFile(strFileName); } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } IElement iElement = (IElement)pictureElement; IActiveView iActiveView = this.m_pMapControl.ActiveView; double pictureWidth = 0; double pictureHeight = 0; pictureElement.QueryIntrinsicSize(ref pictureWidth, ref pictureHeight); IEnvelope env = this.m_pMapControl.ActiveView.Extent; tagRECT rect = new tagRECT(); m_pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.TransformRect(env, ref rect, (int)esriDisplayTransformationEnum.esriTransformToDevice); Rectangle rectangle = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); int x = (rectangle.Left + rectangle.Right) / 2; int y = (rectangle.Top + rectangle.Height) / 2; /* IPoint point = iActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);*/ IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(point.X, point.Y, point.X + (int)(pictureWidth / 72 * iActiveView.ScreenDisplay.DisplayTransformation.ScaleRatio), point.Y + (int)(pictureHeight / 72 * iActiveView.ScreenDisplay.DisplayTransformation.ScaleRatio)); iElement.Geometry = envelope; IBoundsProperties bp = iElement as IBoundsProperties; bp.FixedAspectRatio = true; pictureElement.MaintainAspectRatio = true; pGraphicsContainer = this.m_pMapControl.ActiveView as IGraphicsContainer; pGraphicsContainer.AddElement(iElement, 0); this.m_pMapControl.ActiveView.Refresh(); }