示例#1
0
        public void makeScaleBar(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv)
        {
            IMap pMap = pActiveView.FocusMap;
            IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            if (pStyleGalleryItem == null)
            {
                return;
            }
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame    = pMapFrame;
            pMapSurroundFrame.MapSurround = (IMapSurround)pStyleGalleryItem.Item;
            IElement pElement = axPageLayoutControl1.FindElementByName("ScaleBar");

            if (pElement != null)
            {
                pGraphicsContainer.DeleteElement(pElement);  //删除已经存在的比例尺
            }
            IElementProperties pElePro = null;

            pElement          = (IElement)pMapSurroundFrame;
            pElement.Geometry = (IGeometry)pEnv;
            pElePro           = pElement as IElementProperties;
            pElePro.Name      = "ScaleBar";
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
示例#2
0
        //插入比例尺
        public void InsertScale()
        {
            this.SetCurrentTool();
            AddScaleForm scaleForm = new AddScaleForm();

            if (scaleForm.ShowDialog() == DialogResult.OK)
            {
                IStyleGalleryItem pStyleGalleryItem = scaleForm.m_pStyleGalleryItem;

                IMapFrame         pMapframe      = m_pageLayoutControl.ActiveView.GraphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap) as IMapFrame;
                IMapSurroundFrame pSurroundFrame = new MapSurroundFrameClass();
                pSurroundFrame.MapFrame    = pMapframe;
                pSurroundFrame.MapSurround = (IMapSurround)pStyleGalleryItem.Item;
                //在pageLayout中根据名称查要Element,找到之后删除已经存在的比例尺
                IElement pelement = m_pageLayoutControl.FindElementByName("ScaleBars");
                if (pelement != null)
                {
                    m_pageLayoutControl.ActiveView.GraphicsContainer.DeleteElement(pelement);  //删除已经存在的指北针
                }

                IEnvelope pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(12, 2, 20, 3);

                pelement          = (IElement)pSurroundFrame;
                pelement.Geometry = (IGeometry)pEnvelope;

                m_pageLayoutControl.ActiveView.GraphicsContainer.AddElement(pelement, 0);
                m_pageLayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
        }
示例#3
0
        //创建所有要素的轮廓线
        private void CreateAllElementFrame()
        {
            IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView.GraphicsContainer;

            IElement pElement = pGraphicsContainer.Next();

            //IEnumElement pp =

            IMapSurroundFrame pMapsurroundFrame = new MapSurroundFrameClass();

            pMapsurroundFrame.MapSurround = pGraphicsContainer as IMapSurround;

            IFrameProperties pFrameProperties = pMapsurroundFrame as IFrameProperties;

            //边框的间距和圆角
            if (SymbolBorder != null)
            {
                if (this.txtBorderGap.Text != null)
                {
                    SymbolBorder.Gap = double.Parse(this.txtBorderGap.Text);
                }
                if (this.txtBorderAngle.Text != null)
                {
                    SymbolBorder.CornerRounding = short.Parse(this.txtBorderAngle.Text);
                }
            }
            if (SymbolBackground != null)
            {
                if (txtBackgroundGap.Text != null)
                {
                    SymbolBackground.Gap = double.Parse(this.txtBackgroundGap.Text);
                }
                if (txtBackgroundAngle.Text != null)
                {
                    SymbolBackground.CornerRounding = short.Parse(this.txtBackgroundAngle.Text);
                }
            }
            if (SymbolShadow != null)
            {
                if (txtShadowX.Text != null)
                {
                    SymbolShadow.HorizontalSpacing = double.Parse(this.txtShadowX.Text);
                }
                if (txtShadowY.Text != null)
                {
                    SymbolShadow.VerticalSpacing = double.Parse(this.txtShadowY.Text);
                }
                if (txtShadowAngle.Text != null)
                {
                    SymbolShadow.CornerRounding = short.Parse(this.txtShadowAngle.Text);
                }
            }
            //边框
            pFrameProperties.Border = SymbolBorder;

            //背景
            pFrameProperties.Background = SymbolBackground;
            //阴影
            pFrameProperties.Shadow = SymbolShadow;
        }
示例#4
0
        /// <summary>
        /// 添加比例尺
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        /// <param name="scaleBar">比例尺</param>
        public static void AddScaleBar(AxPageLayoutControl layoutControl, IEnvelope pEnv, IScaleBar2 scaleBar)
        {
            if (scaleBar == null)
            {
                return;
            }
            IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer;

            if (pGraphicsContainer == null)
            {
                return;
            }
            IMap              pMap              = layoutControl.ActiveView.FocusMap;
            IMapFrame         pMapFrame         = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            scaleBar.BarHeight         = pEnv.Height * 10;
            //删除已经存在的比例尺
            MappingHelper.DeleteElementByName(layoutControl, "Scale Line");
            pMapSurroundFrame.MapSurround = scaleBar as IMapSurround;
            IElement pElement = (IElement)pMapSurroundFrame;

            pElement.Geometry = pEnv;
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "Scale Line");
        }
 public override void OnMouseDown(int Button, int Shift, int X, int Y)
 {
     // TODO:  Add AddScaleBar.OnMouseDown implementation
     if (Button == 1)
     {
         IEnvelope pEnv;
         pEnv = pPageLayoutControl.TrackRectangle();
         GetSymbol symbolForm = new GetSymbol(esriSymbologyStyleClass.
                                              esriStyleClassScaleBars);
         symbolForm.Text = "Choose Scale Bar";
         IStyleGalleryItem styleGalleryItem = symbolForm.GetItem
                                                  (esriSymbologyStyleClass.esriStyleClassNorthArrows);
         symbolForm.Dispose();
         if (styleGalleryItem == null)
         {
             return;
         }
         IMapFrame mapFrame = (IMapFrame)m_hookHelper.ActiveView.GraphicsContainer.
                              FindFrame(m_hookHelper.ActiveView.FocusMap);
         IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();
         mapSurroundFrame.MapFrame    = mapFrame;
         mapSurroundFrame.MapSurround = (IMapSurround)styleGalleryItem.Item;
         IElement element = (IElement)mapSurroundFrame;
         element.Geometry = pEnv;
         m_hookHelper.ActiveView.GraphicsContainer.AddElement
             ((IElement)mapSurroundFrame, 0);
         m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,
                                                mapSurroundFrame, null);
     }
 }
示例#6
0
        /// <summary>
        /// 添加默认比例尺
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        /// <param name="pStyleGalleryItem">比例尺样式</param>
        public static void AddDefaultScaleBar(AxPageLayoutControl layoutControl, IEnvelope pEnv, IStyleGalleryItem pStyleGalleryItem)
        {
            if (pStyleGalleryItem == null)
            {
                return;
            }
            IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer;

            if (pGraphicsContainer == null)
            {
                return;
            }
            IMap              pMap              = layoutControl.ActiveView.FocusMap;
            IMapFrame         pMapFrame         = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            //删除已经存在的比例尺
            MappingHelper.DeleteElementByName(layoutControl, "Scale Line");
            IScaleBar2 scaleBar2 = pStyleGalleryItem.Item as IScaleBar2;

            if (scaleBar2 != null)
            {
                scaleBar2.BarHeight           = pEnv.Height * 20;
                scaleBar2.Divisions           = 1;
                scaleBar2.Subdivisions        = 2;
                pMapSurroundFrame.MapSurround = scaleBar2 as IMapSurround;
            }
            IElement pElement = (IElement)pMapSurroundFrame;

            pElement.Geometry = pEnv;
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "Scale Line");
        }
示例#7
0
        /// <summary>
        /// 添加图例
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        /// <param name="pLegend">图例</param>
        public static void AddLegend(AxPageLayoutControl layoutControl, IEnvelope pEnv, ILegend2 pLegend)
        {
            if (pLegend == null)
            {
                return;
            }
            IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer;

            if (pGraphicsContainer == null)
            {
                return;
            }
            IMap      pMap      = layoutControl.ActiveView.FocusMap;
            IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            if (pMapFrame == null)
            {
                return;
            }
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            //如果已经存在图例,删除已经存在的图例
            MappingHelper.DeleteElementByName(layoutControl, "Legend");
            pMapSurroundFrame.MapSurround = pLegend as IMapSurround;
            //添加图例
            IElement pElement = pMapSurroundFrame as IElement;

            pElement.Geometry = pEnv;
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "Legend");
        }
示例#8
0
        /// <summary>
        /// 添加指北针
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        /// <param name="pStyleGalleryItem">指北针样式</param>
        public static void AddNorthArrow(AxPageLayoutControl layoutControl, IEnvelope pEnv, IStyleGalleryItem pStyleGalleryItem)
        {
            if (pStyleGalleryItem == null)
            {
                return;
            }
            IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer;

            if (pGraphicsContainer == null)
            {
                return;
            }
            IMap              pMap              = layoutControl.ActiveView.FocusMap;
            IMapFrame         pMapFrame         = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            //删除已经存在的指北针
            MappingHelper.DeleteElementByName(layoutControl, "North Arrow");
            INorthArrow pNorthArrow = pStyleGalleryItem.Item as INorthArrow;

            if (pNorthArrow != null)
            {
                pNorthArrow.Size = pEnv.Width * 50;
                pMapSurroundFrame.MapSurround = pNorthArrow;//根据用户的选取,获取相应的MapSurround
            }
            IElement pElement = (IElement)pMapSurroundFrame;

            pElement.Geometry = pEnv;
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "North Arrow");
        }
示例#9
0
        void addNorthArrow(IPageLayout pPageLayout, IEnvelope pEnv, IActiveView pActiveView)
        {
            IMap pMap = pActiveView.FocusMap;
            IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            if (pStyleGalleryItem == null)
            {
                return;
            }
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            INorthArrow pNorthArrow = new MarkerNorthArrowClass();

            pNorthArrow      = pStyleGalleryItem.Item as INorthArrow;
            pNorthArrow.Size = pEnv.Width * 50;
            pMapSurroundFrame.MapSurround = (IMapSurround)pNorthArrow;                 //根据用户的选取,获取相应的MapSurround
            IElement pElement = axPageLayoutControl1.FindElementByName("NorthArrows"); //获取PageLayout中的指北针元素

            if (pElement != null)
            {
                pGraphicsContainer.DeleteElement(pElement);  //如果存在指北针,删除已经存在的指北针
            }
            IElementProperties pElePro = null;

            pElement          = (IElement)pMapSurroundFrame;
            pElement.Geometry = (IGeometry)pEnv;
            pElePro           = pElement as IElementProperties;
            pElePro.Name      = "NorthArrows";
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
示例#10
0
        //插入指北针
        public void InsertNorthArrow()
        {
            SetCurrentTool();
            AddNorthArrowForm addNorthArrow = new AddNorthArrowForm();

            if (addNorthArrow.ShowDialog() == DialogResult.OK)
            {
                IStyleGalleryItem pStyleGalleryItemTemp = addNorthArrow.m_pStyleGalleryItem;
                if (pStyleGalleryItemTemp == null)
                {
                    return;
                }

                IMapFrame         pMapframe         = m_pageLayoutControl.ActiveView.GraphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap) as IMapFrame;
                IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();
                pMapSurroundFrame.MapFrame    = pMapframe;
                pMapSurroundFrame.MapSurround = (IMapSurround)pStyleGalleryItemTemp.Item;
                //在pageLayout中根据名称查要Element,找到之后删除已经存在的指北针
                IElement pElement = m_pageLayoutControl.FindElementByName("NorthArrows");
                if (pElement != null)
                {
                    m_pageLayoutControl.ActiveView.GraphicsContainer.DeleteElement(pElement);  //删除已经存在的指北针
                }
                IEnvelope pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(16, 24, 20, 28);

                pElement          = (IElement)pMapSurroundFrame;
                pElement.Geometry = (IGeometry)pEnvelope;

                m_pageLayoutControl.ActiveView.GraphicsContainer.AddElement(pElement, 0);
                m_pageLayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
        }
示例#11
0
        private void CreateNorhtArrow()
        {
            //Create the form with the SymbologyControl
            FrmNorthArrow symbolForm = new FrmNorthArrow(null);

            //Get the IStyleGalleryItem
            if (symbolForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            IStyleGalleryItem styleGalleryItem = symbolForm.GetItem();

            //Release the form
            symbolForm.Dispose();
            if (styleGalleryItem == null)
            {
                return;
            }

            IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView.GraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(m_hookHelper.ActiveView.FocusMap) as IMapFrame;

            if (pMapFrame == null)
            {
                return;
            }

            //Create a map surround frame
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            //Set its map frame and map surround
            pMapSurroundFrame.MapFrame    = pMapFrame;
            pMapSurroundFrame.MapSurround = (IMapSurround)styleGalleryItem.Item;

            //显示结果大小
            IEnvelope   pEnv        = new EnvelopeClass();
            IActiveView pActiveView = m_hookHelper.ActiveView;
            IPageLayout pPageLayout = (IPageLayout)pActiveView;
            IPage       pPage       = pPageLayout.Page;
            double      pWidth      = pPage.PrintableBounds.XMax - 5;
            double      pHeigth     = pPage.PrintableBounds.YMax - 5;

            pEnv.PutCoords(pWidth, pHeigth, pWidth + 20, pHeigth + 20);

            IElement pElement = (IElement)pMapSurroundFrame;

            pElement.Geometry = (IGeometry)pEnv;

            //Add the element to the graphics container
            pGraphicsContainer.AddElement((IElement)pMapSurroundFrame, 0);

            //Refresh
            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
        }
示例#12
0
        public void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            if (m_InUse == false)
            {
                return;
            }

            if (GetCapture() == this.hk.MapControl.ActiveView.ScreenDisplay.hWnd)
            {
                ReleaseCapture();
            }

            if (m_Feedback == null)
            {
                m_Feedback = null;
                m_InUse    = false;
                return;
            }
            IEnvelope envelope = m_Feedback.Stop();

            if ((envelope.IsEmpty) || (envelope.Width == 0) || (envelope.Height == 0))
            {
                m_Feedback = null;
                m_InUse    = false;
                return;
            }

            GetSymbol symbolForm = new GetSymbol(esriSymbologyStyleClass.esriStyleClassNorthArrows);

            symbolForm.Text = "选择指北针";
            IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassNorthArrows);

            symbolForm.Dispose();
            if (styleGalleryItem == null)
            {
                return;
            }

            IMapFrame         mapFrame         = (IMapFrame)this.hk.MapControl.ActiveView.GraphicsContainer.FindFrame(this.hk.MapControl.ActiveView.FocusMap);
            IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();

            mapSurroundFrame.MapFrame    = mapFrame;
            mapSurroundFrame.MapSurround = (IMapSurround)styleGalleryItem.Item;

            IElement element = (IElement)mapSurroundFrame;

            element.Geometry = envelope;

            this.hk.MapControl.ActiveView.GraphicsContainer.AddElement((IElement)mapSurroundFrame, 0);
            this.hk.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, mapSurroundFrame, null);
            m_Feedback = null;
            m_InUse    = false;
        }
        //调用指北针样式
        private void btNAStyle_Click(object sender, EventArgs e)
        {
            //记录原位置
            IEnvelope pEnv = new EnvelopeClass();

            pEnv = m_pElement.Geometry.Envelope;

            //删除原有对象
            m_pGraphicsContainer.DeleteElement(m_pElement);
            //Create the form with the SymbologyControl
            FrmNorthArrow symbolForm = new FrmNorthArrow(m_pNorthArrow);

            //Get the IStyleGalleryItem
            if (symbolForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            IStyleGalleryItem styleGalleryItem = symbolForm.GetItem();

            //Release the form
            symbolForm.Dispose();
            if (styleGalleryItem == null)
            {
                return;
            }

            IMapFrame pMapFrame = m_pGraphicsContainer.FindFrame(m_hookHelper.ActiveView.FocusMap) as IMapFrame;

            if (pMapFrame == null)
            {
                return;
            }

            //Create a map surround frame
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            //Set its map frame and map surround
            pMapSurroundFrame.MapFrame    = pMapFrame;
            pMapSurroundFrame.MapSurround = (IMapSurround)styleGalleryItem.Item;

            m_pElement          = (IElement)pMapSurroundFrame;
            m_pElement.Geometry = (IGeometry)pEnv;

            //Add the element to the graphics container
            m_pGraphicsContainer.AddElement(m_pElement, 0);
            m_pMapFrame   = m_pElement as IMapSurroundFrame;
            m_pNorthArrow = m_pMapFrame.MapSurround as INorthArrow;
            UpdateUI(true);
            //Refresh
            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
        }
 // 添加指北针
 public static void AddNorthArrow(AxPageLayoutControl pageLayoutControl, IEnvelope envelope)
 {
     IMap pMap = pageLayoutControl.ActiveView.FocusMap;
     IGraphicsContainer pGraphicsContariner = pageLayoutControl.PageLayout as IGraphicsContainer;
     IMapFrame          pMapFrame           = pGraphicsContariner.FindFrame(pMap) as IMapFrame;
     IMapSurroundFrame  pMapSurroundFrame   = new MapSurroundFrameClass()
     {
         MapFrame = pMapFrame
     };
     INorthArrow pNorthArrow = new MarkerNorthArrowClass()
     {
         //MarkerSymbol = new MarkerSym
     };
 }
示例#15
0
        private void Btn_AddScaleBar_Click(object sender, EventArgs e)
        {
            FormSymbologySelector formSymbologySelector = new FormSymbologySelector(RequestResponder, esriSymbologyStyleClass.esriStyleClassScaleBars);

            formSymbologySelector.ShowDialog();
            IActiveView       pActiveView       = Ctrl_PageLayout.ActiveView;
            IMap              pMap              = Ctrl_PageLayout.ActiveView.FocusMap;
            IMapFrame         pMapFrame         = (IMapFrame)Ctrl_PageLayout.ActiveView.GraphicsContainer.FindFrame(pMap);
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass
            {
                MapFrame    = pMapFrame,
                MapSurround = (IMapSurround)m_pStyleGalleryItem.Item
            };
            IElement pElement = (IElement)pMapSurroundFrame;

            pElement.Geometry = m_pEnvelopDrawed;
            if (m_pScaleBarElement != null)
            {
                pActiveView.GraphicsContainer.DeleteElement(m_pScaleBarElement);
            }
            pActiveView.GraphicsContainer.AddElement(pElement, 0);
            m_pScaleBarElement = pElement;
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
        }
示例#16
0
        public override void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            if (m_InUse == false) return;

            //Stop capturing mouse events
            if (GetCapture() == m_HookHelper.ActiveView.ScreenDisplay.hWnd)
                ReleaseCapture();

            //If an envelope has not been tracked or its height/width is 0
            if (m_Feedback == null)
            {
                m_Feedback = null;
                m_InUse = false;
                return;
            }
            IEnvelope envelope = m_Feedback.Stop();
            if ((envelope.IsEmpty) || (envelope.Width == 0) || (envelope.Height == 0))
            {
                m_Feedback = null;
                m_InUse = false;
                return;
            }

            //Create the form with the SymbologyControl
            SymbolForm symbolForm = new SymbolForm();
            //Get the IStyleGalleryItem
            IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassScaleBars);
            //Release the form
            symbolForm.Dispose();
            if (styleGalleryItem == null) return;

            //Get the map frame of the focus map
            IMapFrame mapFrame = (IMapFrame) m_HookHelper.ActiveView.GraphicsContainer.FindFrame(m_HookHelper.ActiveView.FocusMap);

            //Create a map surround frame
            IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();
            //Set its map frame and map surround
            mapSurroundFrame.MapFrame = mapFrame;
            mapSurroundFrame.MapSurround = (IMapSurround) styleGalleryItem.Item;

            //QI to IElement and set its geometry
            IElement element = (IElement) mapSurroundFrame;
            element.Geometry = envelope;

            //Add the element to the graphics container
            m_HookHelper.ActiveView.GraphicsContainer.AddElement((IElement)mapSurroundFrame, 0);
            //Refresh
            m_HookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, mapSurroundFrame, null);

            m_Feedback = null;
            m_InUse = false;
        }
示例#17
0
        //创建图例
        private void CreateLegend()
        {
            ILegendFormat     pLegendFormat     = new LegendFormatClass();
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pActiveView = m_hookHelper.ActiveView as IActiveView;
            pMap        = pActiveView.FocusMap;

            //边框、背景、阴影的间距
            if (txtLegendFrameGap.Text != null && pSymbolBorder != null)
            {
                pSymbolBorder.Gap = double.Parse(this.txtLegendFrameGap.Text);
            }
            if (txtLegendFrameGap.Text != null && pSymbolBackground != null)
            {
                pSymbolBackground.Gap = double.Parse(this.txtLegendFrameGap.Text);
            }
            if (txtLegendFrameGap.Text != null && pSymbolShadow != null)
            {
                pSymbolShadow.VerticalSpacing   = double.Parse(this.txtLegendFrameGap.Text) + 10;
                pSymbolShadow.HorizontalSpacing = double.Parse(this.txtLegendFrameGap.Text) + 10;
            }
            //边框、背景、阴影的角度
            if (txtLegendFrameAngle.Text != null && pSymbolBorder != null)
            {
                pSymbolBorder.CornerRounding = short.Parse(txtLegendFrameAngle.Text);
            }
            if (txtLegendFrameAngle.Text != null && pSymbolBackground != null)
            {
                pSymbolBackground.CornerRounding = short.Parse(txtLegendFrameAngle.Text);
            }
            if (txtLegendFrameAngle.Text != null && pSymbolShadow != null)
            {
                pSymbolShadow.CornerRounding = short.Parse(txtLegendFrameAngle.Text);
            }
            //边框、背景、阴影
            IFrameProperties pFrameProperties = pMapSurroundFrame as IFrameProperties;

            if (pSymbolBorder != null)
            {
                pFrameProperties.Border = pSymbolBorder;
            }
            if (pSymbolBackground != null)
            {
                pFrameProperties.Background = pSymbolBackground;
            }
            if (pSymbolShadow != null)
            {
                pFrameProperties.Shadow = pSymbolShadow;
            }

            //显示标题
            pLegendFormat.ShowTitle = true;
            //标题位置
            pLegendFormat.TitlePosition = esriRectanglePosition.esriTopSide;
            //标题样式
            pLegendFormat.TitleSymbol = CreateTitleSymbol();


            //第四界面从上到下图例各部分之间的距离
            pLegendFormat.TitleGap           = double.Parse(txtTitleAndLegend.Text);
            pLegendFormat.VerticalItemGap    = double.Parse(txtLegendItems.Text);
            pLegendFormat.HorizontalItemGap  = double.Parse(txtColumns.Text);
            pLegendFormat.HeadingGap         = double.Parse(txtHeadings.Text);
            pLegendFormat.TextGap            = double.Parse(txtLabelsAndDescription.Text);
            pLegendFormat.VerticalPatchGap   = double.Parse(txtPatchesV.Text);
            pLegendFormat.HorizontalPatchGap = double.Parse(txtPatchAndLabels.Text);

            pLegendFormat.LayerNameGap = 2;

            //图面的样式以及高度和宽度
            if (pLinePatch != null)
            {
                pLegendFormat.DefaultLinePatch = pLinePatch;
            }
            if (pAreaPatch != null)
            {
                pLegendFormat.DefaultAreaPatch = pAreaPatch;
            }
            pLegendFormat.DefaultPatchHeight = double.Parse(this.txtPatchHeight.Text);
            pLegendFormat.DefaultPatchWidth  = double.Parse(this.txtPatchWith.Text);


            //创建图例
            ILegend pLegend = new LegendClass_2();

            //图例名称
            //pLegend.Name = this.txtLegendTitle.Text;
            pLegend.AutoVisibility = false; //显示显示的图层
            pLegend.AutoAdd        = false; //自动添加新数据到图例

            pLegend.AutoReorder = true;     //根据图层顺序自动排列
            pLegend.Title       = this.txtLegendTitle.Text;
            pLegend.Format      = pLegendFormat;

            pLegend.Map = pMap;
            pLegend.ClearItems();
            //pLegend.Refresh();

            //图例列数
            double pLegendColumn = double.Parse(this.LegendColumn.Text);
            //图例中要包含的图层个数为  pSelectedidx.Count
            double pLegendItemCount = pSelectedidx.Count;
            //计算图例分裂的位置
            int    ColumnPos = (int)(pLegendItemCount / pLegendColumn);
            double remainder = (pLegendItemCount % pLegendColumn) / pLegendColumn;

            if (remainder >= 0.5)
            {
                ColumnPos = ColumnPos + 1;
            }
            //设置添加到图例的图层
            for (int i = 0; i < pSelectedidx.Count; i++)
            {
                ILegendItem pLegendItem = new HorizontalLegendItemClass();

                ILayer pLayer = (ILayer)(pMap.get_Layer(pSelectedidx[i]));
                if (!pLayer.Valid)
                {
                    continue;
                }
                pLegendItem.Layer = pLayer;

                //显示标注和描述
                pLegendItem.ShowDescriptions = true;
                pLegendItem.ShowLabels       = true;

                //标注和描述字体样式
                ITextSymbol pLDTextSymbol = new TextSymbolClass();
                IFontDisp   pLDFont       = new StdFontClass() as IFontDisp;
                IRgbColor   pLDColor      = new RgbColorClass();
                pLDColor.Red        = 0;
                pLDColor.Green      = 0;
                pLDColor.Blue       = 0;
                pLDTextSymbol.Color = pLDColor;

                pLDFont.Size       = (decimal)8;
                pLDFont.Name       = "宋体";
                pLDTextSymbol.Font = pLDFont;
                ILegendClassFormat pLegendClassFormat = new LegendClassFormatClass();
                pLegendClassFormat.LabelSymbol       = pLDTextSymbol;
                pLegendClassFormat.DescriptionSymbol = pLDTextSymbol;

                pLegendItem.LegendClassFormat = pLegendClassFormat;
                //图层名称是否显示
                if (pLegendItem.Layer is IFeatureLayer)
                {
                    if (((IGeoFeatureLayer)pLegendItem.Layer).Renderer is ISimpleRenderer)
                    {
                        pLegendItem.ShowHeading   = false;
                        pLegendItem.ShowLayerName = false;
                    }
                    else
                    {
                        pLegendItem.ShowLayerName = true;
                        pLegendItem.ShowHeading   = true;
                        //图层名称和头文件的样式
                        ITextSymbol pLHTextSymbol = new TextSymbolClass();
                        IFontDisp   pLHFont       = new StdFontClass() as IFontDisp;
                        IRgbColor   pLHColor      = new RgbColorClass();
                        pLDColor.Red   = 0;
                        pLDColor.Green = 0;
                        pLDColor.Blue  = 0;

                        pLHTextSymbol.Color = pLHColor;
                        pLHFont.Name        = "宋体";
                        pLHFont.Size        = 10;
                        pLHFont.Bold        = true;
                        pLHTextSymbol.Font  = pLHFont;
                        pLHTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;

                        pLegendItem.HeadingSymbol   = pLHTextSymbol;
                        pLegendItem.LayerNameSymbol = pLHTextSymbol;
                    }
                }
                else if (pLegendItem.Layer is IRasterLayer)
                {
                    pLegendItem.ShowLayerName = true;
                    pLegendItem.ShowHeading   = true;
                    //图层名称和头文件的样式
                    ITextSymbol pLHTextSymbol = new TextSymbolClass();
                    IFontDisp   pLHFont       = new StdFontClass() as IFontDisp;
                    IRgbColor   pLHColor      = new RgbColorClass();
                    pLDColor.Red   = 0;
                    pLDColor.Green = 0;
                    pLDColor.Blue  = 0;

                    pLHTextSymbol.Color = pLHColor;
                    pLHFont.Name        = "宋体";
                    pLHFont.Size        = 10;
                    pLHFont.Bold        = true;
                    pLHTextSymbol.Font  = pLHFont;
                    pLHTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;

                    pLegendItem.HeadingSymbol   = pLHTextSymbol;
                    pLegendItem.LayerNameSymbol = pLHTextSymbol;
                }

                //列数设置
                if (ColumnPos <= 1)
                {
                    pLegendItem.NewColumn = true;
                }
                else if (ColumnPos > 1 && i > 0)
                {
                    int columnI = i % ColumnPos;
                    if (columnI == 0)
                    {
                        pLegendItem.NewColumn = true;
                    }
                }

                ILegendLayout pLegendLayout = pLegendFormat as ILegendLayout;
                pLegendLayout.ScaleGraphicsOnResize = false;


                //将图层及样式设计加入图例中
                pLegend.AddItem(pLegendItem);
                pLegend.Refresh();
            }



            //将图例加载到PageLayout上
            IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            if (pMapFrame == null)
            {
                return;
            }

            pMapSurroundFrame.MapFrame    = pMapFrame;
            pMapSurroundFrame.MapSurround = (IMapSurround)pLegend;
            IElement pElement = (IElement)pMapSurroundFrame;


            IPageLayout pPageLayout = (IPageLayout)pActiveView;
            IPage       pPage       = pPageLayout.Page;
            double      pWidth      = pPage.PrintableBounds.XMax / 10.0;
            double      pHeigth     = pPage.PrintableBounds.YMin / 10.0;

            IEnvelope pEnvelope = new EnvelopeClass();

            pEnvelope.PutCoords(pWidth, pHeigth, pWidth + 6, pHeigth + 6);
            pElement.Geometry = (IGeometry)pEnvelope;

            pGraphicsContainer.AddElement((IElement)pMapSurroundFrame, 0);

            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
        }
示例#18
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (Button == 1)
            {
                IEnvelope pEnv;
                pEnv = pPageLayoutControl.TrackRectangle();

                GetSymbol symbolForm = new GetSymbol(esriSymbologyStyleClass.esriStyleClassScaleTexts );
                symbolForm.Text = "ѡ��������ı�";
                IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassScaleTexts );
                symbolForm.Dispose();
                if (styleGalleryItem == null) return;

                IMapFrame mapFrame = (IMapFrame)m_hookHelper.ActiveView.GraphicsContainer.FindFrame(m_hookHelper.ActiveView.FocusMap);
                IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();
                mapSurroundFrame.MapFrame = mapFrame;
                mapSurroundFrame.MapSurround = (IMapSurround)styleGalleryItem.Item;

                IElement element = (IElement)mapSurroundFrame;
                element.Geometry = pEnv;

                m_hookHelper.ActiveView.GraphicsContainer.AddElement((IElement)mapSurroundFrame, 0);
                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, mapSurroundFrame, null);
            }
        }
示例#19
0
        //创建比例尺
        private void CreateScale()
        {
            if (StyleGalleryItem == null)
            {
                return;
            }

            IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView.GraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(m_hookHelper.ActiveView.FocusMap) as IMapFrame;

            if (pMapFrame == null)
            {
                return;
            }

            if (StyleGalleryItem.Item is IScaleBar)
            {
                IScaleBar pScaleBar = (IScaleBar)StyleGalleryItem.Item;
                pScaleBar.Refresh();
                IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();
                pMapSurroundFrame.MapFrame = pMapFrame;

                pMapSurroundFrame.MapSurround = (IMapSurround)pScaleBar;
                IElement pElement = (IElement)pMapSurroundFrame;

                //添加和指北针一样大小的窗口
                double pScaleBarSize = 15;
                //显示结果大小
                IActiveView pActiveView = m_hookHelper.ActiveView;
                IPageLayout pPageLayout = (IPageLayout)pActiveView;
                IPage       pPage       = pPageLayout.Page;

                double pWidth  = pPage.PrintableBounds.XMin + 2;
                double pHeigth = pPage.PrintableBounds.YMin + 2;

                IEnvelope pEnv = new EnvelopeClass();
                pEnv.PutCoords(pWidth, pHeigth, pWidth + 10, pHeigth + 1);
                pElement.Geometry = (IGeometry)pEnv;

                //Add the element to the graphics container
                pGraphicsContainer.AddElement((IElement)pMapSurroundFrame, 0);
                //Refresh
                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
            }
            else if (StyleGalleryItem.Item is IScaleText)
            {
                IScaleText pScaleText = (IScaleText)StyleGalleryItem.Item;
                pScaleText.Refresh();
                IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();
                pMapSurroundFrame.MapFrame = pMapFrame;

                pMapSurroundFrame.MapSurround = (IMapSurround)pScaleText;
                IElement pElement = (IElement)pMapSurroundFrame;

                //显示结果大小
                IActiveView pActiveView = m_hookHelper.ActiveView;
                IPageLayout pPageLayout = (IPageLayout)pActiveView;
                IPage       pPage       = pPageLayout.Page;


                double pWidth  = pPage.PrintableBounds.XMin + 2;
                double pHeigth = pPage.PrintableBounds.YMin + 2;

                IEnvelope pEnv = new EnvelopeClass();
                pEnv.PutCoords(pWidth, pHeigth, pWidth + 10, pHeigth + 1);
                pElement.Geometry = (IGeometry)pEnv;

                //Add the element to the graphics container
                pGraphicsContainer.AddElement((IElement)pMapSurroundFrame, 0);
                //Refresh
                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
            }
        }
示例#20
0
        //点击地图框事件
        private void axPageLayoutControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e)
        {
            if (e.button == 1)
            {
                IPageLayout        pPageLayout        = axPageLayoutControl1.PageLayout;;
                IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;
                IActiveView        pActiveView        = pPageLayout as IActiveView;
                IMapFrame          pMapFrame;
                IMapSurroundFrame  pMapSurroundFrame;
                IElement           pElement;
                switch (tag)
                {
                    #region 添加标题
                case 1:
                    ITextElement pTextElement = new TextElementClass();
                    pTextElement.Text   = title;
                    pTextElement.Symbol = pTextSymbol;
                    pElement            = pTextElement as IElement;
                    try
                    {
                        pElement.Geometry = axPageLayoutControl1.TrackRectangle();
                    }
                    catch
                    {
                        MessageBox.Show("请拉框选择范围!", "提示");
                        return;
                    }
                    pGraphicsContainer.AddElement(pElement, 0);
                    axPageLayoutControl1.Refresh();
                    tag = 0;
                    break;
                    #endregion

                    #region 添加图例
                case 2:
                    pLegend2 = new LegendClass_2();
                    pElement = axPageLayoutControl1.FindElementByName("legend");
                    if (pElement != null)
                    {
                        pGraphicsContainer.DeleteElement(pElement);
                    }

                    pElementTypeName = "lenend";
                    pUid             = new UIDClass();
                    pUid.Value       = "esriCato.Legend";
                    if (pGraphicsContainer == null)
                    {
                        return;
                    }
                    pMapSurround     = pLegend2 as IMapSurround;
                    pMapSurround.Map = pActiveView.FocusMap;
                    pMapFrame        = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
                    if (pMapFrame == null)
                    {
                        return;
                    }

                    pMapSurroundFrame                  = new MapSurroundFrameClass();
                    pMapSurroundFrame                  = pMapFrame.CreateSurroundFrame(pUid, null);
                    pMapSurroundFrame.MapSurround      = pMapSurround;
                    pMapSurroundFrame.MapSurround.Name = pElementTypeName;
                    pMapSurroundFrame.MapFrame         = pMapFrame;

                    pElement = pMapSurroundFrame as IElement;
                    try
                    {
                        pElement.Geometry = axPageLayoutControl1.TrackRectangle();
                    }
                    catch
                    {
                        MessageBox.Show("请拉框选择范围!", "提示");
                        return;
                    }
                    pElement.Activate(pActiveView.ScreenDisplay);
                    pElement.Draw(pActiveView.ScreenDisplay, null);

                    pGraphicsContainer.AddElement(pElement, 0);
                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

                    //图例标题字体样式
                    pLegend2.Title            = "图例";
                    pTitltFont.Name           = "黑体";
                    pTitltFont.Bold           = true;
                    pTitltFont.Size           = 16;
                    pTitltTextSymbol.Color    = ColorToIColor(Color.Black);
                    pTitltTextSymbol.Font     = pTitltFont;
                    pLenendFormat.TitleSymbol = pTitltTextSymbol;

                    //图例图层名字体样式
                    pLayerFont.Name       = "仿宋_GB2312";
                    pLayerFont.Size       = 13;
                    pLayerTextSymbol.Font = pLayerFont;

                    //图例标签字体样式
                    pLabelFont.Name       = "仿宋_GB2312";
                    pLabelFont.Size       = 13;
                    pLabelTextSymbol.Font = pLayerFont;

                    for (int i = 0; i < pLenendItemsString.Count; i++)
                    {
                        for (int j = 0; j < pLegend2.ItemCount; j++)
                        {
                            if (pLenendItemsString[i].ToString() == pLegend2.get_Item(j).Layer.Name)
                            {
                                pLegend2.RemoveItem(j);
                            }
                        }
                    }
                    pLegend2.AdjustColumns(pColumnCount);
                    pLegend2.Refresh();
                    tag = 0;
                    break;
                    #endregion

                    #region 添加指北针
                case 3:
                    if (pGraphicsContainer == null)
                    {
                        return;
                    }
                    pElement = axPageLayoutControl1.FindElementByName("northarrow");
                    if (pElement != null)
                    {
                        pGraphicsContainer.DeleteElement(pElement);
                    }
                    pElementTypeName = "northarrow";
                    pUid             = new UIDClass();
                    pUid.Value       = "esriCato.MarkerNorthArrow";

                    pMapFrame                     = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
                    pMapSurroundFrame             = new MapSurroundFrameClass();
                    pMapSurroundFrame             = pMapFrame.CreateSurroundFrame(pUid, null);
                    pMapSurroundFrame.MapSurround = pNorthArrowStyleGalleryItem.Item as IMapSurround;
                    pElement = pMapSurroundFrame as IElement;
                    try
                    {
                        pElement.Geometry = axPageLayoutControl1.TrackRectangle();
                    }
                    catch
                    {
                        MessageBox.Show("请拉框选择范围!", "提示");
                        return;
                    }
                    pGraphicsContainer.AddElement(pElement, 0);
                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    tag = 0;
                    break;
                    #endregion

                    #region 添加比例尺
                case 4:
                    if (pGraphicsContainer == null)
                    {
                        return;
                    }
                    pElement = axPageLayoutControl1.FindElementByName("scalebar");
                    if (pElement != null)
                    {
                        pGraphicsContainer.DeleteElement(pElement);
                    }
                    IScaleBar pScaleBar;
                    pScaleBar           = pScaleStyleGalleryItem.Item as IScaleBar;
                    pScaleBar.Units     = esriUnits.esriKilometers;
                    pScaleBar.UnitLabel = " KM";
                    pElementTypeName    = "scalebar";
                    pUid       = new UIDClass();
                    pUid.Value = "esriCato.AlternatingScaleBar";

                    pMapFrame                     = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
                    pMapSurroundFrame             = new MapSurroundFrameClass();
                    pMapSurroundFrame             = pMapFrame.CreateSurroundFrame(pUid, null);
                    pMapSurroundFrame.MapSurround = pScaleStyleGalleryItem.Item as IMapSurround;
                    pElement = pMapSurroundFrame as IElement;
                    try
                    {
                        pElement.Geometry = axPageLayoutControl1.TrackRectangle();
                    }
                    catch
                    {
                        MessageBox.Show("请拉框选择范围!", "提示");
                    }
                    pGraphicsContainer.AddElement(pElement, 0);
                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    tag = 0;
                    break;
                    #endregion
                }
            }
        }
示例#21
0
        public void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            if (m_InUse == false) return;

            if (GetCapture() == this.hk.MapControl.ActiveView.ScreenDisplay.hWnd)
                ReleaseCapture();

            if (m_Feedback == null)
            {
                m_Feedback = null;
                m_InUse = false;
                return;
            }
            IEnvelope envelope = m_Feedback.Stop();
            if ((envelope.IsEmpty) || (envelope.Width == 0) || (envelope.Height == 0))
            {
                m_Feedback = null;
                m_InUse = false;
                return;
            }

            GetSymbol symbolForm = new GetSymbol(esriSymbologyStyleClass.esriStyleClassNorthArrows);
            symbolForm.Text = "ѡ��ָ����";
            IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassNorthArrows);
            symbolForm.Dispose();
            if (styleGalleryItem == null) return;

            IMapFrame mapFrame = (IMapFrame)this.hk.MapControl.ActiveView.GraphicsContainer.FindFrame(this.hk.MapControl.ActiveView.FocusMap);
            IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();
            mapSurroundFrame.MapFrame = mapFrame;
            mapSurroundFrame.MapSurround = (IMapSurround)styleGalleryItem.Item;

            IElement element = (IElement)mapSurroundFrame;
            element.Geometry = envelope;

            this.hk.MapControl.ActiveView.GraphicsContainer.AddElement((IElement)mapSurroundFrame, 0);
            this.hk.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, mapSurroundFrame, null);
            m_Feedback = null;
            m_InUse = false;
        }
示例#22
0
        public override void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            if (m_InUse == false)
            {
                return;
            }

            //Stop capturing mouse events
            if (GetCapture() == m_HookHelper.ActiveView.ScreenDisplay.hWnd)
            {
                ReleaseCapture();
            }

            //If an envelope has not been tracked or its height/width is 0
            if (m_Feedback == null)
            {
                m_Feedback = null;
                m_InUse    = false;
                return;
            }
            IEnvelope envelope = m_Feedback.Stop();

            if ((envelope.IsEmpty) || (envelope.Width == 0) || (envelope.Height == 0))
            {
                m_Feedback = null;
                m_InUse    = false;
                return;
            }

            //Create the form with the SymbologyControl
            SymbolForm symbolForm = new SymbolForm();
            //Get the IStyleGalleryItem
            IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassScaleBars);

            //Release the form
            symbolForm.Dispose();
            if (styleGalleryItem == null)
            {
                return;
            }

            //Get the map frame of the focus map
            IMapFrame mapFrame = (IMapFrame)m_HookHelper.ActiveView.GraphicsContainer.FindFrame(m_HookHelper.ActiveView.FocusMap);

            //Create a map surround frame
            IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();

            //Set its map frame and map surround
            mapSurroundFrame.MapFrame    = mapFrame;
            mapSurroundFrame.MapSurround = (IMapSurround)styleGalleryItem.Item;

            //QI to IElement and set its geometry
            IElement element = (IElement)mapSurroundFrame;

            element.Geometry = envelope;

            //Add the element to the graphics container
            m_HookHelper.ActiveView.GraphicsContainer.AddElement((IElement)mapSurroundFrame, 0);
            //Refresh
            m_HookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, mapSurroundFrame, null);

            m_Feedback = null;
            m_InUse    = false;

            m_PageLayOutControl.CurrentTool = null;
        }
        public override void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            if (m_InUse == false) return;

            //Stop capturing mouse events
            if (GetCapture() == m_HookHelper.ActiveView.ScreenDisplay.hWnd)
                ReleaseCapture();

            //If an envelope has not been tracked or its height/width is 0
            if (m_Feedback == null)
            {
                m_Feedback = null;
                m_InUse = false;
                return;
            }
            IEnvelope envelope = m_Feedback.Stop();
            if ((envelope.IsEmpty) || (envelope.Width == 0) || (envelope.Height == 0))
            {
                m_Feedback = null;
                m_InUse = false;
                return;
            }

            //Create the form with the SymbologyControl
            SymbolForm symbolForm = new SymbolForm();
            //Get the IStyleGalleryItem
            IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassScaleBars);
            //Release the form
            symbolForm.Dispose();
            if (styleGalleryItem == null) return;

            Common.MapPrintCommon.GraphicsContainClearSelection();
            string unit= Common.MapPrintCommon.GetMapUnits();

            //Get the map frame of the focus map
            IMapFrame mapFrame = (IMapFrame) m_HookHelper.ActiveView.GraphicsContainer.FindFrame(m_HookHelper.ActiveView.FocusMap);

            //Create a map surround frame
            IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();
            //Set its map frame and map surround
            mapSurroundFrame.MapFrame = mapFrame;
            mapSurroundFrame.MapSurround = (IMapSurround) styleGalleryItem.Item;

            //QI to IElement and set its geometry
            IElement element = (IElement) mapSurroundFrame;
            element.Geometry = envelope;

            //Add the element to the graphics container
            m_HookHelper.ActiveView.GraphicsContainer.AddElement((IElement)mapSurroundFrame, 0);

            ESRI.ArcGIS.Carto.IScaleBar markerScaleBar = ((ESRI.ArcGIS.Carto.IScaleBar)(mapSurroundFrame.MapSurround));
            markerScaleBar.LabelPosition = ESRI.ArcGIS.Carto.esriVertPosEnum.esriBelow;
            markerScaleBar.UseMapSettings();
            markerScaleBar.UnitLabel = unit;

            //Refresh
            m_HookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, mapSurroundFrame, null);

            m_Feedback = null;
            m_InUse = false;
            Common.MapPrintCommon.g_axPageLayoutControl.CurrentTool = Common.MapPrintCommon.SetControlsSelectCommand();
        }