来自:http://hi.baidu.com/chaisy/blog/item/ad639b584fafbed79c8204b9.html
AE中pagelayout里绘制经纬网
using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.esriSystem;
using System.Runtime.InteropServices;
using System.Drawing;
namespace TMM.MapSurrounds
{
/// <summary>
/// 向Pagelayout上添加格网
/// </summary>
public class AddGrid : BaseCommand
{
/// <summary>
/// 操作的对象
/// </summary>
private IPageLayoutControl3 _pageLayout;
/// <summary>
/// 构造函数 添加格网
/// </summary>
public AddGrid()
{
//设置一些属性
base.m_caption = "添加格网";
base.m_toolTip = "添加格网";
}
/// <summary>
/// 创建
/// </summary>
/// <param name="hook">钩子</param>
public override void OnCreate(object hook)
{
IToolbarControl2 myToolBar = (IToolbarControl2)hook;
this._pageLayout = (IPageLayoutControl3)myToolBar.Buddy;
}
/// <summary>
/// 鼠标点击按钮
/// </summary>
public override void OnClick()
{
this._pageLayout.MousePointer = esriControlsMousePointer.esriPointerHourglass;
//创建一个经纬格网 并设置其相关属性
IMapGrid myMapGrid;
IMeasuredGrid myMeasuredGrid = new MeasuredGridClass();
myMeasuredGrid.FixedOrigin = true;
myMeasuredGrid.Units = this._pageLayout.ActiveView.FocusMap.MapUnits;
myMeasuredGrid.XIntervalSize = 100;
myMeasuredGrid.XOrigin = -300;
myMeasuredGrid.YIntervalSize = 100;
myMeasuredGrid.YOrigin = -300;
myMapGrid = (IMapGrid)myMeasuredGrid;
//设置投影属性
IProjectedGrid myProjectedGrid = (IProjectedGrid)myMeasuredGrid;
myProjectedGrid.SpatialReference = this._pageLayout.ActiveView.FocusMap.SpatialReference;
myMapGrid.Name = "经纬格网";
//创建边线并设置其属性
ICalibratedMapGridBorder myMapGridBorder = new CalibratedMapGridBorderClass();
IColor myColor=new RgbColorClass ();
myColor.RGB = Convert.ToInt32(16711680);
myMapGridBorder.BackgroundColor = myColor;
myColor = new RgbColorClass();
myColor.RGB = Convert.ToInt32(16711680);
myMapGridBorder.ForegroundColor = myColor;
myMapGridBorder.BorderWidth = 3;
myMapGridBorder.Interval = 72;
myMapGridBorder.Alternating = true;
myMapGrid.Border =(IMapGridBorder) myMapGridBorder;
//创建标签,并设置其属性
IFormattedGridLabel myMapFormattedGridLabel = new FormattedGridLabelClass();
IGridLabel myGridLabel = (IGridLabel)myMapFormattedGridLabel;
stdole.StdFont myFont = new stdole.StdFontClass();
myFont.Name = "Arial";
myFont.Size = 16;
myGridLabel.Font = (stdole .IFontDisp)myFont;
myColor = new RgbColorClass();
myColor.RGB = Convert.ToInt32(16711680);
myGridLabel.LabelOffset = 2;
myGridLabel.set_LabelAlignment(esriGridAxisEnum.esriGridAxisLeft, false);
myGridLabel.set_LabelAlignment(esriGridAxisEnum.esriGridAxisRight, false);
INumericFormat myNumericFormat = new NumericFormatClass();
myNumericFormat.AlignmentOption = esriNumericAlignmentEnum.esriAlignRight;
myNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals;
myNumericFormat.RoundingValue = 2;
myNumericFormat.ShowPlusSign = false;
myNumericFormat.UseSeparator = true;
myMapFormattedGridLabel.Format =(INumberFormat) myNumericFormat;
myMapGrid.LabelFormat = myGridLabel;
//添加mapGrid到版式视图
IMapGrids myMapGrids = (IMapGrids)this._pageLayout.ActiveView.GraphicsContainer.FindFrame(this._pageLayout.ActiveView.FocusMap);
myMapGrids.AddMapGrid(myMapGrid);
this._pageLayout.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
this._pageLayout.MousePointer = esriControlsMousePointer.esriPointerArrow;
}
}
}
这是做一个命令按钮 在ToolBarControl加上就行
其实得到的结果是一个 数字为100等数字网格