ArcEngine添加ScaleBar_UnitLabel属性

下面是在布局视图中添加比例尺的代码

            IScaleBar pScaleBar = null;
            IMapFrame pMapFrame;
            IMapSurroundFrame pMapSurroundFrame;
           // IMapSurround pMapSurround;
            IElementProperties pElementPro;
            UID pUID = new UID();
            pUID.Value = "esriCarto.scaleBar";
            IGraphicsContainer pGraphicsContainer;
            pGraphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;
            IActiveView pActiveView;
            pActiveView = pGraphicsContainer as IActiveView;
            IMap pMap;
            pMap = pActiveView.FocusMap;
            pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUID, null);
            switch (3)
            {
                case 0:
                    pScaleBar = new AlternatingScaleBar();
                    break;
                case 1:
                    pScaleBar = new DoubleAlternatingScaleBar();
                    break;
                case 2:
                    pScaleBar = new HollowScaleBar();
                    break;
                case 3:
                    pScaleBar = new ScaleLine();
                    break;
                case 4:
                    pScaleBar = new SingleDivisionScaleBar();
                    break;
                case 5:
                    pScaleBar = new SteppedScaleLine();
                    break;
            }

            //pScaleBar.BarHeight = 2;
            pScaleBar.DivisionsBeforeZero = 0;//设置比例尺原点左侧显示的段数 

            /*****************/
            // pScaleBar.Division = 4;//设置比例尺的分割单位。
            pScaleBar.Divisions = 1;//设置比例尺的总段数。
            pScaleBar.LabelGap = 1;//和标签之间的垂直间隔(1 / 72英寸)
            pScaleBar.LabelPosition = esriVertPosEnum.esriBelow;//比例尺数字标签的显示位置
            pScaleBar.Map = pMap;
            pScaleBar.Name = "比例尺";
            pScaleBar.Subdivisions = 0;//设置主比例尺分为几个子段
            
            pScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarMajorDivisions;
            pScaleBar.UnitLabelGap = 1;
            pScaleBar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAfterLabels;//设置单位标签显示的位置
            pScaleBar.Units = esriUnits.esriKilometers;//设置比例尺的单位
            pScaleBar.UnitLabel = "Kilometers";
 pMapSurroundFrame.MapSurround = pScaleBar; pElementPro = pMapSurroundFrame as IElementProperties;
pElementPro.Name
= "ScaleBar"; IElement pEle = pMapSurroundFrame as IElement;
IEnvelope pEnv = new Envelope() as IEnvelope;
IElement pelement
= (IElement)pMapFrame;
IEnvelope pEnvelope
= pelement.Geometry.Envelope;
//根据名字获取地图对象中的图层 pEnv = new Envelope() as IEnvelope;
pEnv.PutCoords(
2.0435840871, 1.569833139, 20.362010057, 6.5666918);
pEle.Geometry
= pEnv; pGraphicsContainer.AddElement(pEle, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,
null, null);
pScaleBar的UnitLabel属性设置需要放在pScaleBar.Units设置代码之后。这样UnitLabel设置才有效果。


posted on 2015-12-17 18:29  Geography爱好者  阅读(361)  评论(0)    收藏  举报

导航