예제 #1
0
        public void EnableFeatureLayerLabel(IFeatureLayer pFeaturelayer, string sLableField, IRgbColor pRGB, int size, string angleField)
        {
            //判断图层是否为空
            if (pFeaturelayer == null)
            {
                return;
            }
            IGeoFeatureLayer pGeoFeaturelayer = (IGeoFeatureLayer)pFeaturelayer;
            IAnnotateLayerPropertiesCollection pAnnoLayerPropsCollection;

            pAnnoLayerPropsCollection = pGeoFeaturelayer.AnnotationProperties;
            pAnnoLayerPropsCollection.Clear();

            stdole.IFontDisp pFont = new stdole.StdFont() as stdole.IFontDisp;;  //字体
            ITextSymbol      pTextSymbol;

            pFont.Name = "黑体";
            pFont.Size = 4;
            //未指定字体颜色则默认为黑色
            if (pRGB == null)
            {
                pRGB       = new RgbColorClass();
                pRGB.Red   = 0;
                pRGB.Green = 0;
                pRGB.Blue  = 0;
            }

            pTextSymbol       = new TextSymbolClass();
            pTextSymbol.Color = (IColor)pRGB;
            pTextSymbol.Size  = size; //标注大小

            IBasicOverposterLayerProperties4 pBasicOverposterlayerProps4 = new BasicOverposterLayerPropertiesClass();

            switch (pFeaturelayer.FeatureClass.ShapeType)//判断图层类型
            {
            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
                break;

            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
                break;

            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
                break;
            }
            pBasicOverposterlayerProps4.PointPlacementMethod = esriOverposterPointPlacementMethod.esriRotationField;
            //pBasicOverposterlayerProps4.RotationField = angleField;

            ILabelEngineLayerProperties pLabelEnginelayerProps = new LabelEngineLayerPropertiesClass();

            pLabelEnginelayerProps.Expression = "[" + sLableField + "]";
            pLabelEnginelayerProps.Symbol     = pTextSymbol;
            pLabelEnginelayerProps.BasicOverposterLayerProperties = pBasicOverposterlayerProps4 as IBasicOverposterLayerProperties;
            pAnnoLayerPropsCollection.Add((IAnnotateLayerProperties)pLabelEnginelayerProps);
            pGeoFeaturelayer.DisplayAnnotation = true;//很重要,必须设置
            //刷新地图
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
예제 #2
0
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            switch (toolAction)
            {
            case "Drag Zoom In":                                      //判定当前的操作是否为拉框放大

                IEnvelope pEnvelope = axMapControl1.TrackRectangle(); // 调用axMapControl1的矩形框跟踪功能进行拉框操作,
                //将拉框完成后的范围赋值给一个Envelope对象
                //此处,你可以尝试axMapControl1.TrackPolygon(),axMapControl1.TrackCircle(),axMapControl1.TrackLine()等方法的调用,看有什么效果
                if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0) //判定所获取的拉框范围是否无效
                {
                    return;                                                                                  // 拉框范围无效,就直接返回
                }
                axMapControl1.Extent = pEnvelope;                                                            // 给地图窗口的空间范围赋值为刚才拉框的范围
                axMapControl1.ActiveView.Refresh();                                                          //地图刷新
                return;

            case "Drag Zoom Out":                                      //判定当前的操作是否为拉框缩小
                IEnvelope pEnvelope1 = axMapControl1.TrackRectangle(); // 调用axMapControl1的矩形框跟踪功能进行拉框操作,
                //将拉框完成后的范围赋值给一个Envelope对象
                //此处,你可以尝试axMapControl1.TrackPolygon(),axMapControl1.TrackCircle(),axMapControl1.TrackLine()等方法的调用,看有什么效果
                if (pEnvelope1 == null || pEnvelope1.IsEmpty || pEnvelope1.Height == 0 || pEnvelope1.Width == 0)                                                 ////判定所获取的拉框范围是否无效
                {
                    return;                                                                                                                                      //// 拉框范围无效,就直接返回
                }
                IActiveView pActiveView = axMapControl1.ActiveView;                                                                                              // 获取地图视窗对象
                double      mHeight     = pActiveView.Extent.Height * pActiveView.Extent.Height / pEnvelope1.Height;                                             // 根据倍数计算新空间范围高度
                double      mWidth      = pActiveView.Extent.Width * pActiveView.Extent.Width / pEnvelope1.Width;                                                // 根据倍数计算新空间范围宽度
                double      mMinX       = pActiveView.Extent.XMin - (pEnvelope1.XMin - pActiveView.Extent.XMin) * pActiveView.Extent.Width / pEnvelope1.Width;   //计算新空间范围的x的最小值
                double      mMinY       = pActiveView.Extent.YMin - (pEnvelope1.YMin - pActiveView.Extent.YMin) * pActiveView.Extent.Height / pEnvelope1.Height; //计算新空间范围的y的最小值
                double      mMaxX       = mMinX + mWidth;                                                                                                        //计算新空间范围的x的最大值
                double      mMaxY       = mMinY + mHeight;                                                                                                       // 计算新空间范围的y的最大值
                pEnvelope1.PutCoords(mMinX, mMinY, mMaxX, mMaxY);                                                                                                // 给Envelope对象赋值新的空间范围

                //(pActiveView.Extent.XMax-pActiveView.Extent.XMin)*
                axMapControl1.Extent = pEnvelope1;      // 给地图范围赋值为新的空间范围
                axMapControl1.ActiveView.Refresh();     //地图刷新
                return;

            case "Pan":              // 判定是否进行地图平移操作
                axMapControl1.Pan(); //可执行地图平移
                return;

            case "Select Feature Using Point":                                                              //点选要素

                axMapControl1.ActiveView.FocusMap.ClearSelection();                                         // 清空当前地图的选择集;
                axMapControl1.ActiveView.Refresh();
                tagRECT r;                                                                                  //   定义一个tagRECT结构变量,用于存放以当前鼠标为中心的长宽各为10个像素的小矩形
                r.left   = e.x - 5;                                                                         //
                r.right  = e.x + 5;                                                                         //
                r.bottom = e.y - 5;                                                                         //
                r.top    = e.y + 5;                                                                         //
                IEnvelope pEnv = new Envelope() as IEnvelope;                                               // 创建一个Envelope对象,用于接受刚才创建的小矩形范围由屏幕坐标转换为地图坐标的值
                axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, 4); //把r的屏幕坐标转换为地图坐标,存入Envelope对象中
                pEnv.SpatialReference = axMapControl1.ActiveView.FocusMap.SpatialReference;                 //设定Envelope对象的空间坐标参考与当前地图窗口的坐标一致
                IGeometry pGeo = pEnv as IGeometry;                                                         //接口访问到IGeometry接口
                axMapControl1.Map.SelectByShape(pGeo, null, false);                                         //调用地图控件中map对象的SelectByShape方法,在地图中选择与pGeo相交或包含在其中的地图要素
                //int selCount = axMapControl1.Map.SelectionCount;
                //IEnumFeature pEnumFeature = axMapControl1.Map.FeatureSelection as IEnumFeature;
                //IFeature pFeature = pEnumFeature.Next();
                //while (pFeature != null)
                //{
                //    int index = pFeature.Fields.FindField("GB");
                //    str1 = Convert.ToString(pFeature.get_Value(index));
                //    MessageBox.Show(str1);
                //    //string str2 = pFeature.get_Value(2).ToString();
                //    pFeature = pEnumFeature.Next();
                //}



                ISelection        selection         = axMapControl1.Map.FeatureSelection;
                IEnumFeatureSetup iEnumFeatureSetup = (IEnumFeatureSetup)selection;
                iEnumFeatureSetup.AllFields = true;
                IEnumFeature pEnumFeature = (IEnumFeature)iEnumFeatureSetup;
                pEnumFeature.Reset();
                IFeature pFeature = pEnumFeature.Next();
                if (pFeature != null)
                {
                    int index = pFeature.Fields.FindField("RNAME");
                    //string str1 = pFeature.OID.ToString();
                    if (index != -1)
                    {
                        str1 = pFeature.get_Value(index).ToString();
                    }
                    //MessageBox.Show(str1);
                    //pFeature = pEnumFeature.Next();
                }
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);        //

                toolAction = "";
                return;

            case "Select Feature Using Rectangle":                    //矩形选择要素
                IEnvelope pEnvlope2 = axMapControl1.TrackRectangle(); //  进行矩形框的绘制追踪,
                if (pEnvlope2.IsEmpty == true)                        // 若矩形框为空
                {
                    tagRECT r1;
                    r1.left   = e.x - 5;
                    r1.right  = e.x + 5;
                    r1.bottom = e.y - 5;
                    r1.top    = e.y + 5;
                    axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnvlope2, ref r1, 4);
                    pEnvlope2.SpatialReference = axMapControl1.ActiveView.FocusMap.SpatialReference;
                }
                IGeometry pGeo1 = pEnvlope2 as IGeometry;
                axMapControl1.Map.SelectByShape(pGeo1, null, false);
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);


                toolAction = "";
                return;


            case "Select Feature Using Circle":                 // 圆形选择要素
                IGeometry pCircl = axMapControl1.TrackCircle(); //圆形绘制
                if (pCircl.IsEmpty == true)
                {
                    return;
                }
                // IGeometry pGeo1 = pEnvlope2 as IGeometry;
                axMapControl1.Map.SelectByShape(pCircl, null, false);
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                toolAction = "";
                return;

            case "Select Feature Using Polygon":                   //多边形选择要素

                IGeometry pPolygon = axMapControl1.TrackPolygon(); // 绘制多边形
                if (pPolygon.IsEmpty == true)
                {
                    return;
                }
                // IGeometry pGeo1 = pEnvlope2 as IGeometry;
                axMapControl1.Map.SelectByShape(pPolygon, null, false);
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                toolAction = "";
                return;

            case "Select Feature Using Polyline":            // 线性选择要素

                IGeometry pLine = axMapControl1.TrackLine(); //绘制线
                if (pLine.IsEmpty == true)
                {
                    return;
                }
                // IGeometry pGeo1 = pEnvlope2 as IGeometry;
                axMapControl1.Map.SelectByShape(pLine, null, false);
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                toolAction = "";
                return;

            case "Draw Polygon":
                IGeometry pPolygon1 = axMapControl1.TrackPolygon();       // 绘制多边形
                if (pPolygon1 == null)
                {
                    return;
                }
                IElement pElement = new PolygonElement();
                pElement.Geometry = pPolygon1;
                IFillShapeElement pPolygonEle = pElement as IFillShapeElement;
                if (pSelectedFillSymbol != null)
                {
                    pPolygonEle.Symbol = pSelectedFillSymbol;
                }

                IGraphicsContainer pGc = axMapControl1.ActiveView.GraphicsContainer;
                pGc.AddElement(pElement, 0);
                IGraphicsContainerSelect pGSelection = pGc as IGraphicsContainerSelect;
                pGSelection.UnselectAllElements();
                pGSelection.SelectElement(pElement);

                toolAction = "";
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                return;

            case "Draw Point":
                IPoint pPointMark = new ESRI.ArcGIS.Geometry.Point(); // 创建一个点

                pPointMark.PutCoords(e.mapX, e.mapY);                 //给点赋值为当前鼠标所在位置的地图坐标
                IGeometry pPointGeo = pPointMark as IGeometry;
                IElement  pMElement = new MarkerElement();
                pMElement.Geometry = pPointGeo;
                IMarkerElement pMarkElement = pMElement as IMarkerElement;
                if (pSelectedMarkSymbol != null)
                {
                    pMarkElement.Symbol = pSelectedMarkSymbol;
                }

                IGraphicsContainer pGraphiscont = axMapControl1.ActiveView.GraphicsContainer;
                pGraphiscont.AddElement(pMElement, 0);
                IGraphicsContainerSelect pGS = pGraphiscont as IGraphicsContainerSelect;
                pGS.UnselectAllElements();
                pGS.SelectElement(pMElement);

                toolAction = "";
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                return;

            case "Draw Line":
                IGeometry pLineGeo = axMapControl1.TrackLine();       // 绘制Line
                if (pLineGeo == null)
                {
                    return;
                }
                IElement     pElement4 = new LineElement();
                ILineElement pLineEle  = pElement4 as ILineElement;
                if (pSelectedLineSymbol != null)
                {
                    pLineEle.Symbol = pSelectedLineSymbol;
                }

                pElement4.Geometry = pLineGeo;
                IGraphicsContainer pGc4 = axMapControl1.ActiveView.GraphicsContainer;
                pGc4.AddElement(pElement4, 0);
                IGraphicsContainerSelect pGSelection4 = pGc4 as IGraphicsContainerSelect;
                pGSelection4.UnselectAllElements();
                pGSelection4.SelectElement(pElement4);

                toolAction = "";
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                return;

            case "Draw Text":
                IRgbColor pColor = new RgbColor();
                pColor.Red   = 150;
                pColor.Green = 150;
                pColor.Blue  = 0;

                ITextSymbol    pTextSymbol = new TextSymbol();
                stdole.StdFont font        = new stdole.StdFont();
                font.Name         = "宋体";
                font.Size         = 20;
                pTextSymbol.Font  = font as stdole.IFontDisp;
                pTextSymbol.Color = pColor;
                pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                pTextSymbol.VerticalAlignment   = esriTextVerticalAlignment.esriTVABaseline;
                pTextSymbol.Text = "This is my First Text";


                IPoint pTextPoint = new ESRI.ArcGIS.Geometry.Point(); // 创建一个点

                pTextPoint.PutCoords(e.mapX, e.mapY);                 //给点赋值为当前鼠标所在位置的地图坐标
                IGeometry pTextGeo = pTextPoint as IGeometry;

                IElement pTElement = new TextElement();
                pTElement.Geometry = pTextGeo;
                ITextElement pTextEle = pTElement as ITextElement;
                pTextEle.Symbol = pTextSymbol;
                pTextEle.Text   = pTextSymbol.Text;

                IGraphicsContainer pGraphisCon = axMapControl1.ActiveView.GraphicsContainer;
                pGraphisCon.AddElement(pTElement, 0);

                IGraphicsContainerSelect pGrhSelection = pGraphisCon as IGraphicsContainerSelect;
                pGrhSelection.UnselectAllElements();
                pGrhSelection.SelectElement(pTElement);

                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                toolAction = "";
                break;


            case "Select Graphics by using Point":                                                       //通过点击获得GraphicsContainor中的element

                IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();                                        // 创建一个点
                pPoint.PutCoords(e.mapX, e.mapY);                                                        //给点赋值为当前鼠标所在位置的地图坐标
                double                   dist         = axMapControl1.ActiveView.Extent.Width / 15;      //设置以点为圆心的查询的半径
                IGraphicsContainer       pGc1         = axMapControl1.ActiveView.GraphicsContainer;      //获得地图的GraphicsContainor容器
                IEnumElement             pEnumElement = pGc1.LocateElements(pPoint, dist);               //以点为中心点,按照指定半径选择element
                IGraphicsContainerSelect pGSelection1 = pGc1 as IGraphicsContainerSelect;                //获得地图的容器中的图形要素选择集
                if (pEnumElement != null)                                                                //
                {
                    pEnumElement.Reset();                                                                //回到-1位置
                    pGSelection1.UnselectAllElements();                                                  //清空原来选择到的图形要素
                    pGSelection1.SelectElements(pEnumElement);                                           //将新查询到的图形要素添加到GraphicsContainor容器中的图形要素选择集中
                }
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //图形要素刷新

                return;
            }
            if (e.button == 2)                                   //若单击鼠标右键
            {
                contextMenuStrip2.Show(axMapControl1, e.x, e.y); //在TOC控件的当前鼠标位置弹出右键菜单
            }
        }
예제 #3
0
        ///// <summary>
        ///// 构造函数
        ///// </summary>
        ///// <param name="kmlText"></param>
        ///// <param name="layer"></param>
        //public Text_ArcMap(KmlText kmlText, CompositeGraphicsLayerClass compositeGraphicsLayer)
        //{
        //    System.Drawing.Color c = System.Drawing.Color.FromArgb(kmlText.Color);
        //    bTextColor = c;
        //    base.Color = new RgbColorClass() { Red = c.R, Green = c.G, Blue = c.B };
        //    base.Size = kmlText.Size;
        //    bOutLineSize = kmlText.Size;
        //    base.FontName = kmlText.Font;
        //    base.Text = kmlText.Content;
        //    base.Geometry = new PointClass() { X = kmlText.Position.Lng, Y = kmlText.Position.Lat };

        //    this.Description = kmlText.Description;

        //    position = new MapLngLat();
        //    position = kmlText.Position;//坐标点
        //    pIsFlash = false;
        //    flashTimer = new System.Timers.Timer();
        //    flashTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTimer_Elapsed);
        //}

        public Text_ArcMap(AxMapControl _mapControl, KmlText kmlText, FactoryArcMap _mapFactory)
        {
            this.mapControl = _mapControl;
            this.mapFactory = _mapFactory;

            //System.Drawing.Color c = System.Drawing.Color.Red;

            if (mapControl.InvokeRequired)
            {
                mapControl.Invoke((Action) delegate()
                {
                    System.Drawing.Color c = kmlText.Color;

                    textSymbol = new TextSymbolClass();
                    font       = new stdole.StdFontClass();

                    font.Name = kmlText.Font;
                    font.Size = (decimal)kmlText.Size;
                    switch (kmlText.FontStyle)
                    {
                    case FontStyle.Bold:
                        font.Bold          = true;
                        font.Italic        = false;
                        font.Strikethrough = false;
                        font.Underline     = false;
                        break;

                    case FontStyle.Italic:
                        font.Bold          = false;
                        font.Italic        = true;
                        font.Strikethrough = false;
                        font.Underline     = false;
                        break;

                    case FontStyle.Strikeout:
                        font.Bold          = false;
                        font.Italic        = false;
                        font.Strikethrough = true;
                        font.Underline     = false;
                        break;

                    case FontStyle.Underline:
                        font.Bold          = false;
                        font.Italic        = false;
                        font.Strikethrough = false;
                        font.Underline     = true;
                        break;
                    }
                    textSymbol.Font  = font as stdole.IFontDisp;
                    textSymbol.Color = new RgbColorClass()
                    {
                        Red = c.R, Green = c.G, Blue = c.B
                    };
                    //textSymbol.Color.RGB = c.B * 65536 + c.G * 256 + c.G;
                    base.Symbol    = textSymbol;
                    base.Text      = kmlText.Content;
                    base.ScaleText = true;
                    base.Geometry  = new PointClass()
                    {
                        X = kmlText.Position.Lng, Y = kmlText.Position.Lat
                    };
                });
            }
            else
            {
                System.Drawing.Color c = kmlText.Color;

                textSymbol = new TextSymbolClass();
                font       = new stdole.StdFontClass();
                font.Name  = kmlText.Font;
                font.Size  = (decimal)kmlText.Size;
                switch (kmlText.FontStyle)
                {
                case FontStyle.Bold:
                    font.Bold          = true;
                    font.Italic        = false;
                    font.Strikethrough = false;
                    font.Underline     = false;
                    break;

                case FontStyle.Italic:
                    font.Bold          = false;
                    font.Italic        = true;
                    font.Strikethrough = false;
                    font.Underline     = false;
                    break;

                case FontStyle.Strikeout:
                    font.Bold          = false;
                    font.Italic        = false;
                    font.Strikethrough = true;
                    font.Underline     = false;
                    break;

                case FontStyle.Underline:
                    font.Bold          = false;
                    font.Italic        = false;
                    font.Strikethrough = false;
                    font.Underline     = true;
                    break;
                }
                textSymbol.Font  = font as stdole.IFontDisp;
                textSymbol.Color = new RgbColorClass()
                {
                    Red = c.R, Green = c.G, Blue = c.B
                };
                //textSymbol.Color.RGB = c.B * 65536 + c.G * 256 + c.G;
                base.Symbol = textSymbol;

                base.Text      = kmlText.Content;
                base.ScaleText = true;
                base.Geometry  = new PointClass()
                {
                    X = kmlText.Position.Lng, Y = kmlText.Position.Lat
                };
            }

            this.Description = kmlText.Description;
            //记录
            bTextColor   = kmlText.Color;;
            bOutLineSize = kmlText.Size;

            position = new MapLngLat();
            position = kmlText.Position;//坐标点

            flashTimer          = new System.Timers.Timer();
            flashTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTimer_Elapsed);
            flashTimer.Interval = 1000;
        }
예제 #4
0
        private void 添加比例尺ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IActiveView        pActiveView        = axPageLayoutControl1.PageLayout as IActiveView;
            IMap               pMap               = pActiveView.FocusMap as IMap;
            IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IMapSurround       pMapSurround;
            //设置比例尺样式
            IScaleBar pScaleBar = new ScaleLineClass();

            pScaleBar.Units               = esriUnits.esriKilometers;
            pScaleBar.Divisions           = 4;
            pScaleBar.Subdivisions        = 3;
            pScaleBar.DivisionsBeforeZero = 0;
            pScaleBar.UnitLabel           = "km";
            pScaleBar.LabelPosition       = esriVertPosEnum.esriBelow;
            pScaleBar.LabelGap            = 3.6;
            pScaleBar.LabelFrequency      = esriScaleBarFrequency.esriScaleBarDivisionsAndFirstMidpoint;
            pScaleBar.LabelPosition       = esriVertPosEnum.esriBelow;
            ITextSymbol pTextsymbol = new TextSymbolClass();

            pTextsymbol.Size = 1;
            stdole.StdFont pFont = new stdole.StdFont();
            pFont.Size       = 3;
            pFont.Name       = "Arial";
            pTextsymbol.Font = pFont as stdole.IFontDisp;
            pTextsymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
            pScaleBar.UnitLabelSymbol       = pTextsymbol;
            pScaleBar.LabelSymbol           = pTextsymbol;
            INumericFormat pNumericFormat = new NumericFormatClass();

            pNumericFormat.AlignmentWidth = 0;
            pNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits;
            pNumericFormat.RoundingValue  = 0;
            pNumericFormat.UseSeparator   = true;
            pNumericFormat.ShowPlusSign   = false;
            //定义UID
            pMapSurround      = pScaleBar;
            pMapSurround.Name = "ScaleBar";
            UID uid = new UIDClass();

            uid.Value = "esriCarto.ScaleLine";
            //定义MapSurroundFrame对象
            IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(uid, null);

            pMapSurroundFrame.MapSurround = pMapSurround;
            //定义Envelope设置Element摆放的位置
            IEnvelope pEnvelope = new EnvelopeClass();

            pEnvelope.PutCoords(8, 5, 14, 7);
            IElement pElement = pMapSurroundFrame as IElement;

            pElement.Geometry = pEnvelope;
            IElement pDeletElement = axPageLayoutControl1.FindElementByName("ScaleBar");//获取PageLayout中的比例尺元素

            if (pDeletElement != null)
            {
                pGraphicsContainer.DeleteElement(pDeletElement);  //如果已经存在比例尺,删除已经存在的比例尺
            }
            pGraphicsContainer.AddElement(pElement, 0);
            //刷新axPageLayoutControl1的内容
            axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }