arcengine pagelayout控件设置主要代码

文章来自:http://blog.csdn.net/qinyilang/article/details/6331143

private void addtext_Click(object sender, EventArgs e) 
{ 
    ESRI.ArcGIS.Carto.IActiveView activeView; 
    ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer; 
    ESRI.ArcGIS.Carto.ITextElement textElement; 
    ESRI.ArcGIS.Display.ITextSymbol textSymbol; 
    ESRI.ArcGIS.Display.IRgbColor rgbColor; 
    ESRI.ArcGIS.Carto.IElement element; 
    ESRI.ArcGIS.Geometry.IEnvelope envelope; 

    activeView = axPageLayoutControl1.PageLayout as ESRI.ArcGIS.Carto.IActiveView; 
    envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass(); 
    envelope.PutCoords(0, 0, 5, 5); 
    textElement = new ESRI.ArcGIS.Carto.TextElementClass(); 
    element = textElement as ESRI.ArcGIS.Carto.IElement; 
    element.Geometry = envelope; 

    textElement.Text = "我的地图"; 
    textSymbol = new ESRI.ArcGIS.Display.TextSymbolClass(); 
    rgbColor = new ESRI.ArcGIS.Display.RgbColorClass(); 

    rgbColor.Red = 255; 
    rgbColor.Green = 255; 
    rgbColor.Blue = 0; 
    textSymbol.Color = rgbColor as ESRI.ArcGIS.Display.IColor; 
    textSymbol.Size = 20; 
    textElement.Symbol = textSymbol; 

    graphicsContainer = activeView as ESRI.ArcGIS.Carto.IGraphicsContainer; 
    graphicsContainer.AddElement(element, 0); 
    axPageLayoutControl1.Refresh(); 

} 

private void addSymbol_Click(object sender, EventArgs e) 
{ 
    ESRI.ArcGIS.esriSystem.UID uid; 
    ESRI.ArcGIS.Geometry.IEnvelope envelope; 
    ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer; 
    ESRI.ArcGIS.Carto.IMapFrame mapFrame; 
    ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame; 
    ESRI.ArcGIS.Carto.IElement element; 
    ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel; 

    uid = new ESRI.ArcGIS.esriSystem.UIDClass(); 
    uid.Value = "esriCarto.legend"; 
    envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass(); 
    envelope.PutCoords(1,1,2,2); 

    graphicsContainer = axPageLayoutControl1.PageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; 
    mapFrame =graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as ESRI.ArcGIS.Carto.IMapFrame; 
    mapSurroundFrame = mapFrame.CreateSurroundFrame(uid,null); 
    mapSurroundFrame.MapSurround.Name = "图例"; 

    element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; 
    element.Geometry = envelope; 
    element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay); 
    trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); 
    element.Draw(axPageLayoutControl1.ActiveView.ScreenDisplay,trackCancel); 

    graphicsContainer.AddElement(element,0); 
    axPageLayoutControl1.Refresh(); 
} 

private void addtextscaler_Click(object sender, EventArgs e) 
{ 
    UID uid; 
    IEnvelope envelope; 

    IGraphicsContainer graphicsContainer; 
    IMapFrame mapFrame; 
    IMapSurroundFrame mapSurroundFrame; 
    IElement element; 
    ITrackCancel trackCancel; 

    uid = new UIDClass(); 
    uid.Value = "esriCarto.ScaleText"; 
    envelope = new EnvelopeClass(); 
    envelope.PutCoords(1, 1, 2, 2); 

    graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer; 
    mapFrame = graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame; 

    mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); 
    element = mapSurroundFrame as IElement; 
    element.Geometry = envelope; 
    element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay); 

    trackCancel = new TrackCancelClass(); 
    element.Draw(axPageLayoutControl1.ActiveView.ScreenDisplay, trackCancel); 

    graphicsContainer.AddElement(element, 0); 
    axPageLayoutControl1.Refresh(); 
} 

private void addimgscaler_Click(object sender, EventArgs e) 
{ 
    UID uid; 
    IEnvelope envelope; 

    IGraphicsContainer graphicsContainer; 
    IMapFrame mapFrame; 
    IMapSurroundFrame mapSurroundFrame; 
    IElement element; 
    ITrackCancel trackCancel; 

    uid = new UIDClass(); 
    uid.Value = "esriCarto.ScaleLine"; 
    envelope = new EnvelopeClass(); 
    envelope.PutCoords(1, 1, 2, 2); 

    graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer; 
    mapFrame = graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame; 

    mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); 
    element = mapSurroundFrame as IElement; 
    element.Geometry = envelope; 
    element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay); 

    trackCancel = new TrackCancelClass(); 
    element.Draw(axPageLayoutControl1.ActiveView.ScreenDisplay, trackCancel); 

    graphicsContainer.AddElement(element, 0); 
    axPageLayoutControl1.Refresh(); 
}

public void CreateGrid(ESRI.ArcGIS.Carto.IActiveView activeView, IPageLayout pageLayout) 
   { 
       //Create the grid. 
       IMapGrid mapGrid = new GraticuleClass(); 
       mapGrid.Name = "Map Grid"; 

       //Create a color. 
       IColor color = new RgbColorClass(); 
       color.RGB = 0XBBBBBB; // -> Gray. 

       //Set the line symbol used to draw the grid. 
       ICartographicLineSymbol cartographicLineSymbol = new CartographicLineSymbolClass(); 
       cartographicLineSymbol.Cap = esriLineCapStyle.esriLCSButt; 
       cartographicLineSymbol.Width = 2; 
       cartographicLineSymbol.Color = color; 
       mapGrid.LineSymbol = cartographicLineSymbol as ILineSymbol; 
       mapGrid.Border = null; // Clear the default frame border. 

       //Set the Tick properties. 
       mapGrid.TickLength = 15; 
       cartographicLineSymbol = new CartographicLineSymbolClass(); 
       cartographicLineSymbol.Cap = esriLineCapStyle.esriLCSButt; 
       cartographicLineSymbol.Width = 1; 
       cartographicLineSymbol.Color = color; 
       mapGrid.TickLineSymbol = cartographicLineSymbol as ILineSymbol; 
       mapGrid.TickMarkSymbol = null; 

       //Set the SubTick properties. 
       mapGrid.SubTickCount = 5; 
       mapGrid.SubTickLength = 10; 
       cartographicLineSymbol = new CartographicLineSymbolClass(); 
       cartographicLineSymbol.Cap = esriLineCapStyle.esriLCSButt; 
       cartographicLineSymbol.Width = 0.2; 
       cartographicLineSymbol.Color = color; 
       mapGrid.SubTickLineSymbol = cartographicLineSymbol as ILineSymbol; 

       // Set the Grid label properties. 
       IGridLabel gridLabel = mapGrid.LabelFormat; 
       gridLabel.LabelOffset = 15; 

       //Set the Tick, SubTick, and Label Visibility along the four sides of the grid. 
       mapGrid.SetTickVisibility(true, true, true, true); 
       mapGrid.SetSubTickVisibility(true, true, true, true); 
       mapGrid.SetLabelVisibility(true, true, true, true); 

       //Make the map grid visible so it gets drawn when Active View is updated. 
       mapGrid.Visible = true; 

       //Set the IMeasuredGrid properties. 
       IMeasuredGrid measuredGrid = mapGrid as IMeasuredGrid; 
       measuredGrid.FixedOrigin = true; 
       measuredGrid.XIntervalSize = 10; //Meridian interval. 
       measuredGrid.XOrigin = 5; //Shift grid 5°. 
       measuredGrid.YIntervalSize = 10; //Parallel interval. 
       measuredGrid.YOrigin = 5; //Shift grid 5°. 

       // Add the grid to the MapFrame. 
       IMap map = activeView.FocusMap; 
       IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer; 
       IFrameElement frameElement = graphicsContainer.FindFrame(map); 
       IMapFrame mapFrame = frameElement as IMapFrame; 
       IMapGrids mapGrids = null; 
       mapGrids = mapFrame as IMapGrids; 
       mapGrids.AddMapGrid(mapGrid); 

       //Refresh the view. 
       activeView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); 
   } 

 

posted @ 2012-09-14 14:45  叫我小艺  阅读(4237)  评论(0编辑  收藏  举报
给我发邮件(wanganb@126.com)