semon1981
路人甲
路人甲
  • 注册日期2006-06-04
  • 发帖数28
  • QQ
  • 铜币198枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1381回复:0

[求助]在打印模式下移动文本元素的问题

楼主#
更多 发布于:2006-07-02 21:42
<P>在pageLayout 下移动文本元素出现 “对com组件调用返回了错误 HRESULT E_FAIL”,而在移动marker元素时候出现了“尝试读取或写入受保护的内存。这通常是其他内存已经损坏。”但是在移动指南针就没有问题,可以移动,整个地图框也是可以移动的。其中移动文本用的是IMoveTextFeedback,marker元素用的是IMovePointFeedback,而指南针用的是IMovePolygonFeedback。 </P>
<P>程序代码如下:</P>
<P>全局变量</P>
<P>      IElement m_iElement;//移动的元素<BR>        IDisplayFeedback iMoveElementFeedback;</P>
<P>axPageLayoutControl1_OnMouseDown中代码:</P>
<P>//得到鼠标点击位置在地图上的坐标<BR>                        IPoint iPt = axPageLayoutControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);<BR>                        //得到鼠标点击位置的第一个元素(如果存在)<BR>                        //m_iElement = GetHitTest();<BR>                        IEnumElement iEnumElem = axPageLayoutControl1.ActiveView.GraphicsContainer.LocateElements(iPt, 4);</P>
<P>                        //IGraphicsContainerSelect iGraphicsConSelect = axPageLayoutControl1.ActiveView.GraphicsContainer as IGraphicsContainerSelect;<BR>                        //iGraphicsConSelect.UnselectAllElements();<BR>                        //iEnumElem.Reset();<BR>                        //iGraphicsConSelect.SelectElements(iEnumElem);</P>
<P>                        //iView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection, null, null);<BR>                        iEnumElem.Reset();<BR>                        if (iEnumElem != null)<BR>                            m_iElement = iEnumElem.Next();</P>
<P>                        //如果存在一个元素,则检测该元素的类型 (Point, Polyline, Envelope or Polygon)<BR>                        //元素类型<BR>                        IElementProperties iElementPro = m_iElement as IElementProperties;<BR>                        if (m_iElement != null)<BR>                        {<BR>                            //delete this element<BR>                            //axPageLayoutControl1.ActiveView.GraphicsContainer.DeleteElement(m_iElement);<BR>                            //axPageLayoutControl1.ActiveView.Refresh();<BR>                            //return;<BR>                            axPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerSize;<BR>                            IGeometry iGeo = m_iElement.Geometry;<BR>                            //Point<BR>                            if (iElementPro.Type == "Marker")<BR>                            {<BR>                                iMoveElementFeedback = new MovePointFeedbackClass();<BR>                                IMovePointFeedback iMovePtF = iMoveElementFeedback as IMovePointFeedback;<BR>                                iMovePtF.Start(iGeo as IPoint, iPt);<BR>                                <BR>                            }<BR>                            else if(iElementPro.Type == "Text")<BR>                            {<BR>                                iMoveElementFeedback = new MoveTextFeedbackClass();<BR>                                IMoveTextFeedback iMoveTxtF = iMoveElementFeedback as IMoveTextFeedback;<BR>                                iMoveTxtF.Start(iGeo, 10, 10, 2,iPt, 0, false, esriMoveTextConstraints.esriMoveTextConstraintsLeft);<BR>                            }<BR>                                //Data Frame 为地图框架,Map Surround Frame为指南针 <BR>                            else if (iElementPro.Type == "Data Frame" || iElementPro.Type == "Map Surround Frame")<BR>                            {</P>
<P>                                iMoveElementFeedback = new MovePolygonFeedbackClass();<BR>                                IMovePolygonFeedback iMovePolyF = iMoveElementFeedback as IMovePolygonFeedback;<BR>                                iMovePolyF.Start(iGeo as IPolygon, iPt);<BR>                                //MessageBox.Show(iElementPro.Type);<BR>                            }<BR>                            else<BR>                            {<BR>                                MessageBox.Show(iElementPro.Type);<BR>                            }</P>
<P>                        }</P>

<P>axPageLayoutControl1_OnMouseMove中代码</P>
<P>IPoint iPt = axPageLayoutControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);<BR>            <BR>            iMoveElementFeedback.MoveTo(iPt);//移动元素</P>

<P>axPageLayoutControl1_OnMouseUp中代码:</P>
<P>if (m_iElement != null)<BR>            {<BR>                //元素类型<BR>                IElementProperties iElementPro = m_iElement as IElementProperties;<BR>                IGeometry iGeo;<BR>                //Point<BR>                if (iElementPro.Type == "Marker")<BR>                {<BR>                    IMovePointFeedback iMovePtF = iMoveElementFeedback as IMovePointFeedback;<BR>                    iGeo = iMovePtF.Stop();<BR>                    m_iElement.Geometry = iGeo;<BR>                    axPageLayoutControl1.ActiveView.GraphicsContainer.UpdateElement(m_iElement);<BR>                }<BR>                else if (iElementPro.Type == "Text")<BR>                {<BR>                    IMoveTextFeedback iMoveTxtF = iMoveElementFeedback as IMoveTextFeedback;<BR>                    iGeo = iMoveTxtF.Stop();<BR>                    m_iElement.Geometry = iGeo;<BR>                    axPageLayoutControl1.ActiveView.GraphicsContainer.UpdateElement(m_iElement);<BR>                }<BR>                else if (iElementPro.Type == "Data Frame" || iElementPro.Type == "Map Surround Frame")<BR>                {<BR>                    IMovePolygonFeedback iMovePolyF = iMoveElementFeedback as IMovePolygonFeedback;<BR>                    iGeo = iMovePolyF.Stop();<BR>                    m_iElement.Geometry = iGeo;<BR>                    axPageLayoutControl1.ActiveView.GraphicsContainer.UpdateElement(m_iElement);<BR>                }<BR>                else<BR>                    return ;<BR>                iMoveElementFeedback = null;<BR>                m_iElement = null;<BR>                axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);<BR>            }</P>
喜欢0 评分0
游客

返回顶部