修改PageLayout NorthArrow 备注

修改PageLayout中的元素(NorthArrow)获取得到 MapSurroundFrame后,不能直接修改MapSurround属性,否则在删除元素时会出错.首先要将styleGalleryItem.Item 转换为 IMarkerNorthArrow 然后修改 MarkerSymbol 属性

 public override void OnClick()
        {
            // TODO: Add ElementProp.OnClick implementation
            IGraphicsContainerSelect pPageLayoutGraphicsSelect = m_pageLayoutCtrl.PageLayout as IGraphicsContainerSelect;
            IElement pElement = pPageLayoutGraphicsSelect.SelectedElement(0);
            IElementProperties pElementProp = pElement as IElementProperties;
            IStyleGalleryItem styleGalleryItem;

            IEnvelope eExtent=pElement.Geometry.Envelope;  //只在图形的最初始范围

            SymbolForm symbolForm = new SymbolForm();
            //Get the IStyleGalleryItem
        //    System.Windows.Forms.MessageBox.Show(pElementProp.Type);
       //     System.Windows.Forms.MessageBox.Show(pElementProp.Name);
         
            if (pElement is IMapSurroundFrame)
            {
                System.Windows.Forms.MessageBox.Show("是一个IMapSurroundFrame");
                IMapSurroundFrame pMapSf=pElement as IMapSurroundFrame;
               
                IMapSurround pMapSurround = pMapSf.MapSurround;
                if (pMapSurround is ILegend)
                {
                    ILegend pLgd = pMapSurround as ILegend;
                    System.Windows.Forms.MessageBox.Show(pLgd.Title);             
                }
                else if (pMapSurround is IMarkerNorthArrow)
                {
                    styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassNorthArrows);

                   // pMapSf.MapSurround =  (IMapSurround)styleGalleryItem.Item;
                    symbolForm.Dispose();
                    INorthArrow pNArrow= (INorthArrow)pMapSf.MapSurround;
                    IMarkerNorthArrow pmNArrow = (IMarkerNorthArrow)pMapSf.MapSurround;
                  //  ICharacterMarkerSymbol pMarker = pmNArrow.MarkerSymbol as ICharacterMarkerSymbol;
                    IMarkerNorthArrow pMakerNArrowItem = styleGalleryItem.Item as IMarkerNorthArrow;
             //       IMarkerSymbol pMarker=;
                   
                    //cMs.CharacterIndex = 34;
                    pmNArrow.MarkerSymbol = pMakerNArrowItem.MarkerSymbol;

                //    IStyleGalleryItem pMark = styleGalleryItem.Item as ICharacterMarkerSymbol;
                    // if (pMark==null) return;
                 //   pmNArrow.MarkerSymbol = pMark;
                    // pMapSf.MapSurround = pMark;

                    IColor color1=new RgbColorClass();
                    color1.RGB=34567;
                    pNArrow.Color = color1;
                    pNArrow.Refresh();
                }
           //     m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,pMapSf, null);

                //QI to IElement and set its geometry
                 //pElement.Geometry = envelope;
            }
            else if (pElement is IPictureElement)
            {
                System.Windows.Forms.MessageBox.Show("是一个IPictureElement");

            }
            else if (pElement is ITextElement)
            {
                System.Windows.Forms.MessageBox.Show("是一个Textelement");
                ITextElement txtElement = pElement as ITextElement;
                txtElement.Text = "修改标题";
       
            }
            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null, null);
        }

posted on 2008-02-19 21:47  xc#  阅读(946)  评论(0编辑  收藏  举报