private void SetMapFrame()//设置地图基本信息,如比例尺,图例等: { IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)this.axPageLayoutControl1.ActiveView; pGraphicsContainer.Reset(); IElementProperties pElementProperties = (IElementProperties)pGraphicsContainer.Next(); while (pElementProperties != null) { if (pElementProperties is ITextElement) //设置文本 { ITextElement ptextElement = new TextElementClass(); ptextElement = (ITextElement)pElementProperties; if (ptextElement.Text.Trim() == "双击添加标题" || ptextElement.Symbol.Size > 25) { ptextElement.Text = m_textTitle; } if (ptextElement.Text.Trim().Contains("坐标系")) { ptextElement.Text = "坐标系:" + m_textProject + "\r" + "高程系:" + m_textElevation; } if (ptextElement.Text.Trim().Contains("制作者")) { ptextElement.Text = "制图人:" + m_textName + "\r" + "制作时间:" + m_textDate; } } if (pElementProperties.Type == "Map Surround Frame") { IMapSurroundFrame pMapSurrounFrame = pElementProperties as IMapSurroundFrame; IElement pElement = (IElement)pElementProperties; if (pMapSurrounFrame.MapSurround.Name.Trim() == "Legend") { ILegend pLegend = pMapSurrounFrame.MapSurround as ILegend; pLegend.Map = m_Map; // IMapSurround pMapSurround = pMapSurrounFrame.MapSurround; //pElement = pMapSurrounFrame.MapSurround as IElement; // pMapSurround.Map = m_Map; // m_Map.AddMapSurround(pMapSurround); } if (pMapSurrounFrame.MapSurround.Name == "Alternating Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Stepped Scale Line" || pMapSurrounFrame.MapSurround.Name == "Scale Line" || pMapSurrounFrame.MapSurround.Name == "Hollow Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Single Division Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Double Alternating Scale Bar") { // m_Map.MapScale = 5000; IScaleBar pScaleBar = pMapSurrounFrame.MapSurround as IScaleBar; pScaleBar.Map = m_Map; pScaleBar.Units = m_Map.MapUnits; pScaleBar.UseMapSettings(); pElement = pMapSurrounFrame.MapSurround as IElement; } if (pMapSurrounFrame.MapSurround.Name == "Scale Text") { IScaleText pScaleText = pMapSurrounFrame.MapSurround as IScaleText; pScaleText.Map = m_Map; } if (pMapSurrounFrame.MapSurround.Name == "North Arrow") { INorthArrow pNorthArrow = pMapSurrounFrame.MapSurround as INorthArrow; pNorthArrow.Map = m_Map; } } if (pElementProperties.Type == "Data Frame") { IFrameElement pFrameElement = pElementProperties as IFrameElement; IMapFrame pMapframe = pFrameElement as IMapFrame; // pMapframe.ExtentType = esriExtentTypeEnum.esriExtentBounds; IMapGrids pmapGrids = pMapframe as IMapGrids; IMapGrid pMapGrid = null; for (int i = 0; i < pmapGrids.MapGridCount; i++) { pMapGrid = pmapGrids.get_MapGrid(i); //用户要求显示与否 pMapGrid.Visible = true; } } pElementProperties = (IElementProperties)pGraphicsContainer.Next(); } if (axPageLayoutControl1.Page.Orientation == 2) { IPaper paper; paper = new PaperClass(); //create a paper object IPrinter printer; printer = new EmfPrinterClass(); //create a printer object paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32()); paper.Orientation = 2; printer.Paper = paper; axPageLayoutControl1.Printer = printer; pageSetupDialog1.PageSettings.Landscape = true; pageSetupDialog1.AllowOrientation = true; } if (axPageLayoutControl1.Page.Orientation == 1 && axPageLayoutControl1.Printer.Paper.Orientation == 2) { IPaper paper; paper = new PaperClass(); //create a paper object IPrinter printer; printer = new EmfPrinterClass(); //create a printer object paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32()); paper.Orientation = 1; printer.Paper = paper; axPageLayoutControl1.Printer = printer; pageSetupDialog1.PageSettings.Landscape = false; pageSetupDialog1.AllowOrientation = true; } }
private void axPageLayoutControl1_OnDoubleClick(object sender, IPageLayoutControlEvents_OnDoubleClickEvent e) { if (m_element != null) { IElementProperties pElementProp = m_element as IElementProperties; if (pElementProp.Type == "Text") { ITextElement pTextElement = pElementProp as ITextElement; frmTextSymbol frmText = new frmTextSymbol(ref pTextElement); frmText.ShowDialog(); pElementProp = pTextElement as IElementProperties; m_pageLayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection, null, null); m_pageLayoutControl.ActiveView.Refresh(); } else if (pElementProp.Type == "Map Surround Frame") { IMapSurroundFrame pMapSurrounFrame = pElementProp as IMapSurroundFrame; if (pMapSurrounFrame.MapSurround.Name == "Legend") { frmLegendWizard frmLegedWizard = new frmLegendWizard(m_Map, m_pageLayoutControl, pMapSurrounFrame); frmLegedWizard.ShowDialog(); //修改图例属性 } else if (pMapSurrounFrame.MapSurround.Name == "Alternating Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Hollow Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Double lternating Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Scale Line" || pMapSurrounFrame.MapSurround.Name == "Single Division Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Stepped Scale Line") { ESRI.ArcGIS.Controls.esriSymbologyStyleClass styleClass = esriSymbologyStyleClass.esriStyleClassScaleBars; frmLegendItemSymbol frmScaleBar = new frmLegendItemSymbol(); IStyleGalleryItem pstyGallertItem = frmScaleBar.GetItem(styleClass);//获取样式 IScaleBar pscaleBar = pMapSurrounFrame.MapSurround as IScaleBar; esriUnits punits = pscaleBar.Units; if (pstyGallertItem != null) { pscaleBar = (IScaleBar)pstyGallertItem.Item; } else { return; } pscaleBar.Map = m_pageLayoutControl.ActiveView.FocusMap; //重新设置比例尺依附的地图及单位 pscaleBar.Units = punits; pscaleBar.UseMapSettings(); pscaleBar.Refresh(); pMapSurrounFrame.MapSurround = pscaleBar as IMapSurround; //旧的比例尺样式转换为新的比例尺样式 m_pageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); //刷新 } else if (pMapSurrounFrame.MapSurround.Name == "Scale Text") { frmLegendItemSymbol frmTextScal = new frmLegendItemSymbol(); IStyleGalleryItem pStyGalleryItem = frmTextScal.GetItem(esriSymbologyStyleClass.esriStyleClassScaleTexts); IScaleText pScaleText = pMapSurrounFrame.MapSurround as IScaleText; esriUnits pUnits = pScaleText.MapUnits; if (pStyGalleryItem != null) { pScaleText = (IScaleText)pStyGalleryItem.Item; } else { return; } pScaleText.Map = m_pageLayoutControl.ActiveView.FocusMap; pScaleText.MapUnits = pScaleText.MapUnits; pMapSurrounFrame.MapSurround = pScaleText as IMapSurround; m_pageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } else if (pMapSurrounFrame.MapSurround.Name.Trim() == "North Arrow") { INorthArrow northArrow = pMapSurrounFrame.MapSurround as INorthArrow; frmNorthArrowSymbol frmNorthArrow = new frmNorthArrowSymbol(); IStyleGalleryItem pstyGallertItem = frmNorthArrow.GetItem(esriSymbologyStyleClass.esriStyleClassNorthArrows);; if (pstyGallertItem != null) { northArrow = (INorthArrow)pstyGallertItem.Item; northArrow.CalibrationAngle = frmNorthArrow.Angle(); } else { return; } pMapSurrounFrame.MapSurround = (IMapSurround)northArrow; m_pageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } } } }
private static void old_acctor_mc() { m_pScaleText = null; }