///<summary>Add a Scale Bar to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///
        ///<remarks></remarks>
        public void AddScalebar(IPageLayout pageLayout, IMap map)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(7, 1, 25, 1.5); // Specify the location and size of the scalebar
            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.AlternatingScaleBar";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;                    // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView        activeView        = pageLayout as ESRI.ArcGIS.Carto.IActiveView;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement      frameElement      = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = frameElement as ESRI.ArcGIS.Carto.IMapFrame;                           // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement           element           = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement;                        // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;


            ESRI.ArcGIS.Carto.IScaleBar markerScaleBar = ((ESRI.ArcGIS.Carto.IScaleBar)(mapSurround));

            markerScaleBar.LabelSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(20)
            };
            markerScaleBar.UnitLabelSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(20)
            };

            markerScaleBar.LabelPosition = ESRI.ArcGIS.Carto.esriVertPosEnum.esriBelow;
            markerScaleBar.UseMapSettings();
        }
Exemplo n.º 2
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;
            }

            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();
        }