MainFrm.cs
上传用户:songlsx
上传日期:2022-06-19
资源大小:2227k
文件大小:99k
源码类别:

GIS编程

开发平台:

Visual C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using ESRI.ArcGIS.Carto;
  9. using ESRI.ArcGIS.Controls;
  10. using ESRI.ArcGIS.esriSystem;
  11. using ESRI.ArcGIS.Display;
  12. using ESRI.ArcGIS.Geometry;
  13. using ESRI.ArcGIS.SystemUI;
  14. using ESRI.ArcGIS.Geodatabase;
  15. using ESRI.ArcGIS.DataSourcesFile;
  16. namespace LinGIS
  17. {
  18.     public partial class MainFrm : DevComponents.DotNetBar.Office2007RibbonForm
  19.     {
  20.         private FeatLyrFrm newFeatLyrFrm;
  21.         private ESRI.ArcGIS.Controls.IMapControl3 m_mapControl = null;
  22.         private ESRI.ArcGIS.Controls.IPageLayoutControl2 m_pageLayoutControl = null;
  23.         private ControlsSynchronizer m_controlsSynchronizer = null;
  24.         private IMapDocument pMapDocument;
  25.         
  26.         public MainFrm()
  27.         {
  28.             InitializeComponent();
  29.         }
  30.         
  31.         private void MainFrm_Load(object sender, EventArgs e)
  32.         {
  33.             //get a reference to the MapControl and the PageLayoutControl
  34.             //取得MapControl和PageLayoutControl的引用
  35.             m_mapControl = (IMapControl3)this.mainMapControl.Object;
  36.             m_pageLayoutControl = (IPageLayoutControl2)this.axPageLayoutControl.Object;
  37.             //initialize the controls synchronization calss
  38.             //初始化controls synchronization calss
  39.             m_controlsSynchronizer = new ControlsSynchronizer(m_mapControl, m_pageLayoutControl);
  40.             //bind the controls together (both point at the same map) and set the MapControl as the active control
  41.             //把MapControl和PageLayoutControl帮顶起来(两个都指向同一个Map),然后设置MapControl为活动的Control
  42.             m_controlsSynchronizer.BindControls(true);
  43.             //add the framework controls (TOC and Toolbars) in order to synchronize then when the
  44.             //active control changes (call SetBuddyControl)
  45.             //m_controlsSynchronizer.AddFrameworkControl(axToolbarControl1.Object);
  46.             //m_controlsSynchronizer.AddFrameworkControl(axToolbarControl2.Object);
  47.             m_controlsSynchronizer.AddFrameworkControl(this.axTOCControl.Object);
  48.             //add the Open Map Document command onto the toolbar
  49.             //OpenNewMapDocument openMapDoc = new OpenNewMapDocument(m_controlsSynchronizer);
  50.             //axToolbarControl1.AddItem(openMapDoc, -1, 0, false, -1, esriCommandStyles.esriCommandStyleIconOnly);
  51.         }
  52.         private ILayer TOCRightLayer;
  53.         private void axTOCControl_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
  54.         {
  55.             esriTOCControlItem itemType = esriTOCControlItem.esriTOCControlItemNone;
  56.             IBasicMap basicMap = null;
  57.             ILayer layer = null;
  58.             object unk = null;
  59.             object data = null;
  60.             //this.axTOCControl.GetSelectedItem(ref itemType, ref basicMap, ref layer, ref unk, ref data);
  61.             this.axTOCControl.HitTest(e.x,e.y,ref itemType, ref basicMap, ref layer, ref unk, ref data);
  62.             if (e.button == 2)
  63.             {
  64.                 //switch (itemType)
  65.                 //{
  66.                 //    case esriTOCControlItem.esriTOCControlItemNone:
  67.                 //        MessageBox.Show("None");
  68.                 //        break;
  69.                 //    case esriTOCControlItem.esriTOCControlItemMap:
  70.                 //        MessageBox.Show("Mapn" + basicMap.Name);
  71.                 //        break;
  72.                 //    case esriTOCControlItem.esriTOCControlItemLayer:
  73.                 //        MessageBox.Show("Layern" + layer.Name);
  74.                 //        break;
  75.                 //    case esriTOCControlItem.esriTOCControlItemLegendClass:
  76.                 //        MessageBox.Show("Legendn" + ((ILegendGroup)unk).get_Class((int)data).Description + "n" + ((ILegendGroup)unk).get_Class((int)data).Label);
  77.                 //        break;
  78.                 //    case esriTOCControlItem.esriTOCControlItemHeading:
  79.                 //        MessageBox.Show("Headingn" + ((ILegendGroup)unk).Heading);
  80.                 //        break;
  81.                 //}
  82.                 switch (itemType)
  83.                 {
  84.                     case esriTOCControlItem.esriTOCControlItemLayer:
  85.                         this.TOCRightLayer = layer;
  86.                         this.contextMenuTOCFeatureLyr.Show(this.axTOCControl, e.x, e.y);
  87.                         break;
  88.                     case esriTOCControlItem.esriTOCControlItemMap:
  89.                         this.contextMenuTOCMap.Show(this.axTOCControl, e.x, e.y);
  90.                         break;
  91.                 }
  92.             }
  93.             if (e.button == 1)
  94.             {
  95.                 switch (itemType)
  96.                 {
  97.                     case esriTOCControlItem.esriTOCControlItemLegendClass:
  98.                         ILegendClass pLegendClass = ((ILegendGroup)unk).get_Class((int)data);
  99.                         SymbolSelectorFrm newSymbolSelectorFrm = new SymbolSelectorFrm(pLegendClass, layer);
  100.                         if (newSymbolSelectorFrm.ShowDialog() == DialogResult.OK)
  101.                         {
  102.                             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  103.                             pLegendClass.Symbol = newSymbolSelectorFrm.pSymbol;
  104.                             this.axTOCControl.Update();
  105.                         }
  106.                         break;
  107.                 }
  108.             }
  109.         }
  110.         
  111.         private void axTOCControl_OnDoubleClick(object sender, ITOCControlEvents_OnDoubleClickEvent e)
  112.         {
  113.             esriTOCControlItem itemType = esriTOCControlItem.esriTOCControlItemNone;
  114.             IBasicMap basicMap = null;
  115.             ILayer layer = null;
  116.             object unk = null;
  117.             object data = null;
  118.             this.axTOCControl.HitTest(e.x, e.y, ref itemType, ref basicMap, ref layer, ref unk, ref data);
  119.             //this.axTOCControl.GetSelectedItem(ref itemType, ref basicMap, ref layer, ref unk, ref data);
  120.             //if (itemType == esriTOCControlItem.esriTOCControlItemLayer)
  121.             //{
  122.             //    if (layer is IGeoFeatureLayer)
  123.             //    {
  124.             //        FeatLyrFrm newFeatLyrFrm = new FeatLyrFrm(layer);
  125.             //        newFeatLyrFrm.Show();
  126.             //    }
  127.             //}
  128.             switch (itemType)
  129.             {
  130.                 case esriTOCControlItem.esriTOCControlItemLayer:
  131.                     if (layer is IGeoFeatureLayer)
  132.                     {
  133.                         if (this.newFeatLyrFrm == null)
  134.                         {
  135.                             this.newFeatLyrFrm = new FeatLyrFrm();
  136.                         }
  137.                         this.newFeatLyrFrm.Layer = layer;
  138.                         if (this.newFeatLyrFrm.ShowDialog() == DialogResult.OK)
  139.                         {
  140.                             this.mainMapControl.Refresh();
  141.                             this.EagleaxMapControl.Refresh();
  142.                             this.axTOCControl.Update();
  143.                         }
  144.                     }
  145.                     break;
  146.                 case esriTOCControlItem.esriTOCControlItemLegendClass:
  147.                     break;
  148.             }
  149.             
  150.         }
  151.        
  152.         private IColor getRGBColor(int r, int g, int b)
  153.         {
  154.             IRgbColor pRgbColor = new RgbColorClass();
  155.             pRgbColor.Red = r;
  156.             pRgbColor.Green = g;
  157.             pRgbColor.Blue = b;
  158.             IColor pColor = pRgbColor as IColor;
  159.             return pColor;
  160.         }
  161.         private IHsvColor getHsvColor(int hue, int saturation, int value)
  162.         {
  163.             IHsvColor pHsvColor = new HsvColorClass();
  164.             pHsvColor.Hue = hue;
  165.             pHsvColor.Saturation = saturation;
  166.             pHsvColor.Value = value;
  167.             return pHsvColor;
  168.         }
  169.         #region 专题图按钮
  170.         private void btnSimpleRender_Click(object sender, EventArgs e)
  171.         {
  172.             ISimpleFillSymbol pSimpleFillSym = new SimpleFillSymbolClass();
  173.             pSimpleFillSym.Color = getRGBColor(255, 0, 0);
  174.             pSimpleFillSym.Style = esriSimpleFillStyle.esriSFSSolid;
  175.             ISimpleRenderer pSimpleRender = new SimpleRendererClass();
  176.             pSimpleRender.Symbol = pSimpleFillSym as ISymbol;
  177.             pSimpleRender.Label = "haha";
  178.             pSimpleRender.Description = "hoho";
  179.             ITransparencyRenderer pTransRenderer = pSimpleRender as ITransparencyRenderer;
  180.             pTransRenderer.TransparencyField = "GDP_1999(";//透明字段
  181.             IGeoFeatureLayer pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer;
  182.             pGeoFeatLyr.Renderer = pTransRenderer as IFeatureRenderer;
  183.             this.mainMapControl.Refresh(esriViewDrawPhase.esriViewBackground, null, null);
  184.             //this.axTOCControl.SetBuddyControl(this.mainMapControl.Object);
  185.             this.axTOCControl.Update();
  186.         }
  187.         private void btnClassBreakRender_Click(object sender, EventArgs e)
  188.         {
  189.             //先用一个ITableHistogram对象从一个要素类获取某一字段的所有值及频率,即dataValues和dataFrequency,这两个数组是分组的基本数据
  190.             //取得两个数组后,系统用IClassGEN对象对它们进行分级,得到classes及classCount,前者是分级临界点值的数组,后者为分级数目
  191.             //根据得到的分级数目和颜色带对象,可以分别设置ClassBreakRender对象的不同符号,产生不同的效果
  192.             IGeoFeatureLayer pGeoFeatLyr;
  193.             ITable pTable;
  194.             
  195.             object dataValues;
  196.             object dataFrequency;
  197.             string strOutput;
  198.             pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer;
  199.             pTable = pGeoFeatLyr as ITable;
  200.             //以下代码用TableHistogram和BasicHistogram统计出Table某一字段的值和值的频率
  201.             ITableHistogram pTableHistogram;
  202.             pTableHistogram = new BasicTableHistogramClass();
  203.             pTableHistogram.Table = pTable;//需传入一个ITable
  204.             pTableHistogram.Field = "GDP_1999(";//统计的字段
  205.             IBasicHistogram pBasicHistogram;
  206.             pBasicHistogram = pTableHistogram as IBasicHistogram;
  207.             pBasicHistogram.GetHistogram(out dataValues, out dataFrequency);//关键
  208.             //以下代码用IClassifyGEN和EqualInterval对象,基于分段数目,生成各段的临界值,并放在一个数组当中
  209.             IClassifyGEN pClassifyGen = new EqualIntervalClass();
  210.             double[] classes;
  211.             int classCount = 5;
  212.             pClassifyGen.Classify(dataValues, dataFrequency, ref classCount);//用到了上面ITableHistogram生成的值和值频率数组,关键!!!!!!
  213.             classes = pClassifyGen.ClassBreaks as double[];//注意,此对象下标从1开始(我觉得0为最开头,所以临界值从1开始有意义),关键!!!!!!
  214.             //classCount = classes.Length; 此处应该为6
  215.             //for (int i = 0; i < classes.Length; i++)
  216.             //{
  217.             //    MessageBox.Show(classes[i].ToString());
  218.             //}
  219.             //MessageBox.Show(classCount.ToString());
  220.             IClassBreaksRenderer pClassBreakRenderer = new ClassBreaksRendererClass();//设置分段着色属性
  221.             pClassBreakRenderer.Field = "GDP_1999(";
  222.             pClassBreakRenderer.BreakCount = 5;//分成5段
  223.             pClassBreakRenderer.SortClassesAscending = true;
  224.             //以下代码生成颜色带
  225.             IHsvColor pFromColor = getHsvColor(60, 100, 96);
  226.             IHsvColor pToColor = getHsvColor(0, 100, 96);
  227.             IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();
  228.             pColorRamp.FromColor = pFromColor as IColor;
  229.             pColorRamp.ToColor = pToColor as IColor;
  230.             pColorRamp.Size = classCount;//生成颜色的数目
  231.             //MessageBox.Show(classCount.ToString());
  232.             bool ok;
  233.             pColorRamp.CreateRamp(out ok);//创建颜色带,关键!!!
  234.             if (ok)//如果颜色带成功生成的话
  235.             {
  236.                 IEnumColors pEnumColors = pColorRamp.Colors;//存放生成颜色带的各颜色
  237.                 pEnumColors.Reset();//是必须吗?????关键!!!
  238.                 
  239.                 IColor pColor;
  240.                 ISimpleFillSymbol pSimpleFillSymbol;
  241.                 //ISimpleMarkerSymbol pSimpleMarkerSymbol;
  242.                 for (int i = 0; i < classCount; i++)//为每个值范围设置符号(此处为SimpleFillSymbol)
  243.                 {
  244.                     pColor = pEnumColors.Next();
  245.                     pSimpleFillSymbol = new SimpleFillSymbolClass();
  246.                     pSimpleFillSymbol.Color = pColor;
  247.                     pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
  248.                     //pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();
  249.                     //pSimpleMarkerSymbol.Color = pColor;
  250.                     pClassBreakRenderer.set_Symbol(i, (ISymbol)pSimpleFillSymbol);//设置Symbol,关键!!!
  251.                     pClassBreakRenderer.set_Break(i, classes[i + 1]);//设置临界值,注意下标,关键!!!
  252.                 }
  253.                 pGeoFeatLyr.Renderer = pClassBreakRenderer as IFeatureRenderer;
  254.                 this.mainMapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
  255.                 //this.axTOCControl.SetBuddyControl(this.mainMapControl.Object);
  256.                 this.axTOCControl.Update();
  257.             }
  258.         }
  259.         private void UniqueValueRender_Click(object sender, EventArgs e)
  260.         {
  261.             //
  262.             ITable pTable= (ITable)this.mainMapControl.get_Layer(0);
  263.             int fieldIndex = pTable.FindField("NAME");//取得"NAME"字段的index,关键
  264.             
  265.             IQueryFilter pQueryFilter = new QueryFilterClass();
  266.             pQueryFilter.WhereClause = "";
  267.             pQueryFilter.AddField("NAME");
  268.             //IFeatureCursor pFeatureCursor = pTable.Search(pQueryFilter, false);
  269.             
  270.             int rowCount = pTable.RowCount(pQueryFilter);//取得"NAME"字段有值得行的数目,关键!!!!!
  271.             //以下代码创建并设置随机颜色带对象,并生成颜色
  272.             IRandomColorRamp pColorRamp = new RandomColorRampClass();
  273.             pColorRamp.StartHue = 0;
  274.             pColorRamp.MinValue = 99;
  275.             pColorRamp.MinSaturation = 15;
  276.             pColorRamp.EndHue = 360;
  277.             pColorRamp.MaxValue = 100;
  278.             pColorRamp.MaxSaturation = 30;
  279.             pColorRamp.Size = rowCount;
  280.             bool ok = true;
  281.             pColorRamp.CreateRamp(out ok);//产生颜色
  282.             
  283.             if (ok)
  284.             {
  285.                 IEnumColors pEnumColors = pColorRamp.Colors;
  286.                 
  287.                 ISimpleFillSymbol pSimpleFillSymbol;
  288.                 IRowBuffer pRowBuffer;
  289.                 IColor pColor;
  290.                 string value;
  291.                 IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();//创建着色对象
  292.                 pUniqueValueRenderer.FieldCount = 1;//设置只对一个字段进行着色
  293.                 pUniqueValueRenderer.set_Field(0, "NAME");
  294.                 for (int i = 0; i < rowCount; i++)
  295.                 {
  296.                     pRowBuffer = (IRowBuffer)pTable.GetRow(i);//关键,用于取得字段值
  297.                     value = pRowBuffer.get_Value(fieldIndex).ToString();
  298.                     pColor = pEnumColors.Next();
  299.                     pSimpleFillSymbol = new SimpleFillSymbolClass();
  300.                     pSimpleFillSymbol.Color = pColor;
  301.                     pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
  302.                     pUniqueValueRenderer.AddValue(value, "", (ISymbol)pSimpleFillSymbol);//为每个唯一值设置Symbol,关键!!!!!!
  303.                 }
  304.                 //ITransparencyRenderer pTransparencyRenderer = pUniqueValueRenderer as ITransparencyRenderer;
  305.                 //pTransparencyRenderer.TransparencyField = "";
  306.                 
  307.                 ((IGeoFeatureLayer)pTable).Renderer = pUniqueValueRenderer as IFeatureRenderer;
  308.                 this.mainMapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
  309.                 //this.axTOCControl.SetBuddyControl(this.mainMapControl.Object);
  310.                 this.axTOCControl.Update();
  311.             }
  312.         }
  313.         private void btnProportionalSymbolRender_Click(object sender, EventArgs e)
  314.         {
  315.             IGeoFeatureLayer pGeoFeatLyr = (IGeoFeatureLayer)this.mainMapControl.get_Layer(0);
  316.             ITable pTable = pGeoFeatLyr as ITable;
  317.             IQueryFilter pQueryFilter = new QueryFilterClass();
  318.             pQueryFilter.AddField("GDP_1999(");
  319.             pQueryFilter.WhereClause = "";
  320.             ICursor pCursor;//DataStatistic对象统计需要用一个Cursor
  321.             pCursor = pTable.Search(pQueryFilter, true);
  322.             IDataStatistics pDataStatistics = new DataStatisticsClass();//用于统计字段信息,需要一个Cursor
  323.             pDataStatistics.Cursor = pCursor;
  324.             pDataStatistics.Field = "GDP_1999(";
  325.             IStatisticsResults pStatisticsResults;//字段统计结果
  326.             pStatisticsResults = pDataStatistics.Statistics;
  327.                             
  328.             ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();//用于背景
  329.             pSimpleFillSymbol.Color = this.getHsvColor(60, 120, 60);
  330.             ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();//标注符号(最小),注意size属性
  331.             pSimpleMarkerSymbol.Color = this.getHsvColor(120, 100, 75);
  332.             pSimpleMarkerSymbol.Size = 0.5;
  333.             //以下创建并设置着色对象
  334.             IProportionalSymbolRenderer pProportionalSymbolRenderer = new ProportionalSymbolRendererClass();
  335.             pProportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits;
  336.             pProportionalSymbolRenderer.Field = "GDP_1999(";
  337.             pProportionalSymbolRenderer.FlanneryCompensation = false;
  338.             pProportionalSymbolRenderer.MinDataValue = 1;//为什么用pStatisticsResults.Minimum会出错??????????
  339.             pProportionalSymbolRenderer.MaxDataValue = pStatisticsResults.Maximum;
  340.             pProportionalSymbolRenderer.BackgroundSymbol = pSimpleFillSymbol as IFillSymbol;
  341.             pProportionalSymbolRenderer.MinSymbol = pSimpleMarkerSymbol as ISymbol;//最小值的符号,关键!!!!!!!
  342.             pProportionalSymbolRenderer.LegendSymbolCount = 3;
  343.             pProportionalSymbolRenderer.CreateLegendSymbols();
  344.             pGeoFeatLyr.Renderer = pProportionalSymbolRenderer as IFeatureRenderer;
  345.             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  346.             this.axTOCControl.Update();
  347.         }
  348.         private void btnStackedChartRender_Click(object sender, EventArgs e)
  349.         {
  350.             IGeoFeatureLayer pGeoFeatLyr = (IGeoFeatureLayer)this.mainMapControl.get_Layer(0);
  351.             double p1, p2, max;//比较制作专题图所用两个字段的最大值的最大
  352.             ICursor pCursor = (ICursor)pGeoFeatLyr.Search(null, true);
  353.             IDataStatistics pDataStatistics = new DataStatisticsClass();
  354.             pDataStatistics.Cursor = pCursor;
  355.             pDataStatistics.Field = "GDP_1999(";
  356.             p1 = pDataStatistics.Statistics.Maximum;
  357.             pCursor = (ICursor)pGeoFeatLyr.Search(null, true);//重新设置Cursor,为什么一定要这样?
  358.             //pDataStatistics.Cursor = null;
  359.             pDataStatistics.Cursor = pCursor;
  360.             pDataStatistics.Field = "GDP_1994(";
  361.             p2 = pDataStatistics.Statistics.Maximum;
  362.             //MessageBox.Show(p1.ToString() + "n" + p2.ToString());
  363.             max = p1 > p2 ? p1 : p2;
  364.             //以下创造3个SimpleFillSymbol,供下面使用
  365.             ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
  366.             pSimpleFillSymbol.Color = getRGBColor(255, 0, 0);
  367.             pSimpleFillSymbol.Outline = null;
  368.             ISimpleFillSymbol pSimpleFillSymbol2 = new SimpleFillSymbolClass();
  369.             pSimpleFillSymbol2.Color = getRGBColor(0, 0, 255);
  370.             pSimpleFillSymbol2.Outline = null;
  371.             ISimpleFillSymbol pSimpleFillSymbol3 = new SimpleFillSymbolClass();
  372.             pSimpleFillSymbol3.Color = getRGBColor(0, 255, 0);
  373.             //以下代码设置StackedChart符号,和StackedChart符号的各符号
  374.             IStackedChartSymbol pStackedChartSymbol = new StackedChartSymbolClass();//Stached符号
  375.             pStackedChartSymbol.Width = 6;//宽度
  376.             pStackedChartSymbol.Fixed = false;//不固定长度
  377.             IChartSymbol pChartSymbol = pStackedChartSymbol as IChartSymbol;
  378.             pChartSymbol.MaxValue = max;//必须
  379.             IMarkerSymbol pMarkerSymbol = pStackedChartSymbol as IMarkerSymbol;
  380.             pMarkerSymbol.Size = 60;//符号大小
  381.             ISymbolArray pSymbolArray = pStackedChartSymbol as ISymbolArray;//SymbolArray
  382.             pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol);//添加符号
  383.             pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol2);//添加符号
  384.             //以下代码设置着色对象
  385.             IChartRenderer pChartRenderer = new ChartRendererClass();
  386.             IRendererFields pRendererFields = pChartRenderer as IRendererFields;
  387.             pRendererFields.AddField("GDP_1999(", "GDP_1999(");
  388.             pRendererFields.AddField("GDP_1994(", "GDP_1994(");
  389.             pChartRenderer.ChartSymbol = (IChartSymbol)pStackedChartSymbol;//设置符号
  390.             pChartRenderer.Label = "GDP";
  391.             pChartRenderer.BaseSymbol = pSimpleFillSymbol3 as ISymbol;//背景
  392.             pChartRenderer.UseOverposter = true;//防止重叠
  393.             pChartRenderer.CreateLegend();//创造图例,关键!!!!!!!!!
  394.             pGeoFeatLyr.Renderer = (IFeatureRenderer)pChartRenderer;
  395.             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  396.             this.axTOCControl.Update();
  397.         }
  398.         private void btnBarChartRender_Click(object sender, EventArgs e)//此专题图制作跟StackedChart差不多
  399.         {
  400.             IGeoFeatureLayer pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer;
  401.             
  402.             //用DataStatistics对象,得到两个字段最大值的较大值(最最大)
  403.             double p1, p2, max;
  404.             ICursor pCursor = (ICursor)pGeoFeatLyr.Search(null, true);
  405.             IDataStatistics pDataStatistics = new DataStatisticsClass();
  406.             pDataStatistics.Cursor = pCursor;
  407.             pDataStatistics.Field = "GDP_1999(";
  408.             p1 = pDataStatistics.Statistics.Maximum;
  409.             pCursor = (ICursor)pGeoFeatLyr.Search(null, true);
  410.             pDataStatistics.Cursor = pCursor;
  411.             pDataStatistics.Field = "GDP_1994(";
  412.             p2 = pDataStatistics.Statistics.Maximum;
  413.             max = p1 > p2 ? p1 : p2;
  414.             
  415.             //以下生成好三个SimpleFillSymbol,留作后用
  416.             ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
  417.             pSimpleFillSymbol.Color = getRGBColor(255, 0, 0);
  418.             pSimpleFillSymbol.Outline = null;
  419.             ISimpleFillSymbol pSimpleFillSymbol2 = new SimpleFillSymbolClass();
  420.             pSimpleFillSymbol2.Color = getRGBColor(0, 0, 255);
  421.             pSimpleFillSymbol2.Outline = null;
  422.             ISimpleFillSymbol pSimpleFillSymbol3 = new SimpleFillSymbolClass();
  423.             pSimpleFillSymbol3.Color = getRGBColor(0, 255, 0);
  424.             
  425.             //创建并设置BarChartSymbol,以及设置好BarChartSymbol里的各自Symbol
  426.             IBarChartSymbol pBarChartSymbol = new BarChartSymbolClass();
  427.             pBarChartSymbol.Width = 6;//宽度
  428.             pBarChartSymbol.Spacing = 1;//Bar之间的间隔
  429.             IChartSymbol pChartSymbol = pBarChartSymbol as IChartSymbol;
  430.             pChartSymbol.MaxValue = max;//用到了上面求出的最大值
  431.             ISymbolArray pSymbolArray = pBarChartSymbol as ISymbolArray;//用于在BarChartSymbol里添加Symbol,关键
  432.             pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol);
  433.             pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol2);
  434.             IMarkerSymbol pMarkerSymbol = pBarChartSymbol as IMarkerSymbol;
  435.             pMarkerSymbol.Size = 60;//BarChartSymbol符号大小
  436.             
  437.             //以下创建并设置着色对象
  438.             IChartRenderer pChartRenderer = new ChartRendererClass();
  439.             IRendererFields pRendererFields = pChartRenderer as IRendererFields;//添加用于着色的字段,关键
  440.             pRendererFields.AddField("GDP_1994(", "GDP_1994(");
  441.             pRendererFields.AddField("GDP_1999(", "GDP_1999(");
  442.             pChartRenderer.ChartSymbol = pChartSymbol;//赋给上面创建的BarChartSymbol
  443.             pChartRenderer.BaseSymbol = pSimpleFillSymbol3 as ISymbol;
  444.             pChartRenderer.Label = "GDP";
  445.             pChartRenderer.UseOverposter = true;
  446.             pChartRenderer.CreateLegend();//创建图例,关键
  447.             pGeoFeatLyr.Renderer = pChartRenderer as IFeatureRenderer;
  448.             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  449.             this.axTOCControl.Update();
  450.         }
  451.         private void btnPieChartRender_Click(object sender, EventArgs e)
  452.         {
  453.             IGeoFeatureLayer pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer;
  454.             //找出两个用于着色字段的最大值的最大值(这次加上最小值之和,这个函数的尾后部分用到,用于在着色对象里确定最小的PieChartSymbol的大小)
  455.             double p1, p2, max, m1, m2, min;
  456.             ICursor pCursor = pGeoFeatLyr.Search(null, true) as ICursor;
  457.             IDataStatistics pDataStatistics = new DataStatisticsClass();
  458.             pDataStatistics.Cursor = pCursor;
  459.             pDataStatistics.Field = "GDP_1994(";
  460.             p1 = pDataStatistics.Statistics.Maximum;
  461.             m1 = pDataStatistics.Statistics.Minimum;
  462.             pCursor = pGeoFeatLyr.Search(null, true) as ICursor;
  463.             pDataStatistics.Cursor = pCursor;
  464.             pDataStatistics.Field = "GDP_1999(";
  465.             p2 = pDataStatistics.Statistics.Maximum;
  466.             m2 = pDataStatistics.Statistics.Minimum;
  467.             max = p1 > p2 ? p1 : p2;
  468.             min = m1 + m2;//最小值之和
  469.             //以下生成好三个SimpleFillSymbol,留作后用
  470.             ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
  471.             pSimpleFillSymbol.Color = getRGBColor(255, 0, 0);
  472.             pSimpleFillSymbol.Outline = null;
  473.             ISimpleFillSymbol pSimpleFillSymbol2 = new SimpleFillSymbolClass();
  474.             pSimpleFillSymbol2.Color = getRGBColor(0, 0, 255);
  475.             pSimpleFillSymbol2.Outline = null;
  476.             ISimpleFillSymbol pSimpleFillSymbol3 = new SimpleFillSymbolClass();
  477.             pSimpleFillSymbol3.Color = getRGBColor(0, 255, 0);
  478.             //以下创建并设置PieChartSymbol对象,并设置PieChartSymbol对象的各个SimpleFillSymbol
  479.             IPieChartSymbol pPieChartSymbol = new PieChartSymbolClass();
  480.             pPieChartSymbol.Clockwise = true;
  481.             pPieChartSymbol.UseOutline = false;
  482.             IChartSymbol pChartSymbol = pPieChartSymbol as IChartSymbol;
  483.             pChartSymbol.MaxValue = max;
  484.             ISymbolArray pSymbolArray = pPieChartSymbol as ISymbolArray;
  485.             pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol);
  486.             pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol2);
  487.             IMarkerSymbol pMarkerSymbol = pPieChartSymbol as IMarkerSymbol;
  488.             pMarkerSymbol.Size = 5;//PieChartSymbol的大小(我觉得是饼的厚度)
  489.             
  490.             //以下创建并设置着色对象
  491.             IChartRenderer pChartRenderer = new ChartRendererClass();
  492.             pChartRenderer.BaseSymbol = pSimpleFillSymbol3 as ISymbol;
  493.             pChartRenderer.ChartSymbol = pChartSymbol;
  494.             pChartRenderer.UseOverposter = true;
  495.             pChartRenderer.Label = "GDP";
  496.             IPieChartRenderer pPieChartRenderer = pChartRenderer as IPieChartRenderer;
  497.             pPieChartRenderer.MinSize = 0.5;//最小的尺码关键
  498.             pPieChartRenderer.MinValue = 1;//最小尺码的值,为什么0不可以??????????????关键
  499.             pPieChartRenderer.ProportionalBySum = true;//PieChartSymbol的大小按照字段和成比例,关键
  500.                                                        //若PieChartSymbol的大小只按一个字段,则须设置.ProportionalField为该字段
  501.             IRendererFields pRenderFields = pChartRenderer as IRendererFields;//添加用于着色的字段
  502.             pRenderFields.AddField("GDP_1994(", "GDP_1994(");
  503.             pRenderFields.AddField("GDP_1999(", "GDP_1999(");
  504.             pChartRenderer.CreateLegend();//生成图例
  505.             pGeoFeatLyr.Renderer = pChartRenderer as IFeatureRenderer;
  506.             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  507.             this.axTOCControl.Update();
  508.         }
  509.         private void btnDotDensityRender_Click(object sender, EventArgs e)
  510.         {
  511.             IGeoFeatureLayer pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer;
  512.             
  513.             //创建SimpleMarkerSymbol,将会用在DotDensitySymbol中
  514.             IMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass();
  515.             pMarkerSymbol.Color = getRGBColor(255, 0, 0);
  516.             
  517.             //创建并设置DotDensitySymbol,以及DotDensitySymbol中的Symbol(上面的MarkerSymbol)
  518.             IDotDensityFillSymbol pDotDensityFillSymbol = new DotDensityFillSymbolClass();
  519.             pDotDensityFillSymbol.DotSize = 5;//大小
  520.             pDotDensityFillSymbol.Color = getRGBColor(0, 255, 0);//此颜色不知为何物???????????
  521.             pDotDensityFillSymbol.BackgroundColor = getRGBColor(239, 228, 190);
  522.             ISymbolArray pSymbolArray = pDotDensityFillSymbol as ISymbolArray;
  523.             pSymbolArray.AddSymbol((ISymbol)pMarkerSymbol);//添加符号,关键
  524.             
  525.             //以下创建并设置着色对象
  526.             IDotDensityRenderer pDotDensityRenderer = new DotDensityRendererClass();
  527.             pDotDensityRenderer.DotDensitySymbol = pDotDensityFillSymbol;//着色对象所用的DotDensitySymbol
  528.             pDotDensityRenderer.DotValue = 100;//一个点代表的值,关键!!!
  529.             pDotDensityRenderer.MaintainSize = true;//地图缩放时DotDensitySymbol符号大小保持
  530.             IRendererFields pRendererFields = pDotDensityRenderer as IRendererFields;
  531.             pRendererFields.AddField("GDP_1999(", "GDP_1999(");//用于着色的字段,关键
  532.             pDotDensityRenderer.CreateLegend();
  533.             pGeoFeatLyr.Renderer = pDotDensityRenderer as IFeatureRenderer;
  534.             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  535.             this.axTOCControl.Update();
  536.         }
  537.         private void btnAnno_Click(object sender, EventArgs e)
  538.         {
  539.             IGeoFeatureLayer pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer;
  540.             //获得AnnotateLayerPropertiesCollection
  541.             IAnnotateLayerPropertiesCollection pAnnoLyrProCollection = pGeoFeatLyr.AnnotationProperties;
  542.             pAnnoLyrProCollection.Clear();
  543.             //创建并设置TextSymbol
  544.             ITextSymbol pTextSymbol = new TextSymbolClass();
  545.             System.Drawing.Font pFont = new System.Drawing.Font("Castellar", 15.0F);
  546.             pTextSymbol.Font = ESRI.ArcGIS.Utility.COMSupport.OLE.GetIFontDispFromFont(pFont) as stdole.IFontDisp;//转换.NET的Font
  547.             pTextSymbol.Color = getRGBColor(255, 0, 0);
  548.             //创建LineLabelPosition
  549.             ILineLabelPosition pLineLabelPosition = new LineLabelPositionClass();
  550.             pLineLabelPosition.Parallel = false;
  551.             pLineLabelPosition.Perpendicular = true;
  552.             //创建LineLabelPlacementPriorities
  553.             ILineLabelPlacementPriorities pLineLablePlacementPriorities = new LineLabelPlacementPrioritiesClass();
  554.             //创建BasicOverposterLayerProperties
  555.             IBasicOverposterLayerProperties pBasicOverposterLayerProperties = new BasicOverposterLayerPropertiesClass();
  556.             pBasicOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
  557.             pBasicOverposterLayerProperties.LineLabelPlacementPriorities = pLineLablePlacementPriorities;
  558.             pBasicOverposterLayerProperties.LineLabelPosition = pLineLabelPosition;
  559.             //创建LabelEngineLayerProperties
  560.             ILabelEngineLayerProperties pLabelEnginLayerProperties = new LabelEngineLayerPropertiesClass();
  561.             pLabelEnginLayerProperties.Symbol = pTextSymbol;
  562.             pLabelEnginLayerProperties.BasicOverposterLayerProperties = pBasicOverposterLayerProperties;
  563.             pLabelEnginLayerProperties.Expression = "[NAME]";
  564.             IAnnotateLayerProperties pAnnoLyrPro = pLabelEnginLayerProperties as IAnnotateLayerProperties;
  565.             pAnnoLyrProCollection.Add(pAnnoLyrPro);//添加,关键
  566.             pGeoFeatLyr.DisplayAnnotation = true;//确定显示
  567.             this.mainMapControl.Refresh();
  568.         }
  569.         #endregion
  570.         #region tools工具条制作
  571.         //private void btnZoomIn_Click(object sender, EventArgs e)
  572.         //{
  573.         //    ICommand pCommand = new ControlsMapZoomInToolClass();
  574.         //    ITool pTool = pCommand as ITool;
  575.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  576.         //    {
  577.         //        pCommand.OnCreate(this.mainMapControl.Object);
  578.         //        this.mainMapControl.CurrentTool = pTool;
  579.         //    }
  580.         //    else
  581.         //    {
  582.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  583.         //        this.axPageLayoutControl.CurrentTool = pTool;
  584.         //    }
  585.         //}
  586.         //private void btnZoomOut_Click(object sender, EventArgs e)
  587.         //{
  588.         //    ICommand pCommand = new ControlsMapZoomOutToolClass();
  589.         //    ITool pTool = pCommand as ITool;
  590.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  591.         //    {
  592.         //        pCommand.OnCreate(this.mainMapControl.Object);
  593.         //        this.mainMapControl.CurrentTool = pTool;
  594.         //    }
  595.         //    else
  596.         //    {
  597.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  598.         //        this.axPageLayoutControl.CurrentTool = pTool;
  599.         //    }
  600.         //}
  601.         //private void btnFixedZoomIn_Click(object sender, EventArgs e)
  602.         //{
  603.         //    ICommand pCommand = new ControlsMapZoomInFixedCommandClass();
  604.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  605.         //    {
  606.         //        pCommand.OnCreate(this.mainMapControl.Object);
  607.         //        pCommand.OnClick();
  608.         //    }
  609.         //    else
  610.         //    {
  611.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  612.         //        pCommand.OnClick();
  613.         //    }
  614.         //}
  615.         //private void btnFixedZoomOut_Click(object sender, EventArgs e)
  616.         //{
  617.         //    ICommand pCommand = new ControlsMapZoomOutFixedCommandClass();
  618.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  619.         //    {
  620.         //        pCommand.OnCreate(this.mainMapControl.Object);
  621.         //        pCommand.OnClick();
  622.         //    }
  623.         //    else
  624.         //    {
  625.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  626.         //        pCommand.OnClick();
  627.         //    }
  628.         //}
  629.         //private void btnPan_Click(object sender, EventArgs e)
  630.         //{
  631.         //    ICommand pCommand = new ControlsMapPanToolClass();
  632.         //    ITool pTool = pCommand as ITool;
  633.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  634.         //    {
  635.         //        pCommand.OnCreate(this.mainMapControl.Object);
  636.         //        this.mainMapControl.CurrentTool = pTool;
  637.         //    }
  638.         //    else
  639.         //    {
  640.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  641.         //        this.axPageLayoutControl.CurrentTool = pTool;
  642.         //    }
  643.         //}
  644.         //private void btnFullExtent_Click(object sender, EventArgs e)
  645.         //{
  646.         //    ICommand pCommand = new ControlsMapFullExtentCommandClass();
  647.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  648.         //    {
  649.         //        pCommand.OnCreate(this.mainMapControl.Object);
  650.         //        pCommand.OnClick();
  651.         //    }
  652.         //    else
  653.         //    {
  654.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  655.         //        pCommand.OnClick();
  656.         //    }
  657.         //}
  658.         //private void btnPreviousExtent_Click(object sender, EventArgs e)
  659.         //{
  660.         //    ICommand pCommand = new ControlsMapZoomToLastExtentBackCommandClass();
  661.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  662.         //    {
  663.         //        pCommand.OnCreate(this.mainMapControl.Object);
  664.         //        pCommand.OnClick();
  665.         //    }
  666.         //    else
  667.         //    {
  668.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  669.         //        pCommand.OnClick();
  670.         //    }
  671.         //}
  672.         //private void btnNextExtent_Click(object sender, EventArgs e)
  673.         //{
  674.         //    ICommand pCommand = new ControlsMapZoomToLastExtentForwardCommandClass();
  675.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  676.         //    {
  677.         //        pCommand.OnCreate(this.mainMapControl.Object);
  678.         //        pCommand.OnClick();
  679.         //    }
  680.         //    else
  681.         //    {
  682.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  683.         //        pCommand.OnClick();
  684.         //    }
  685.         //}
  686.         //private void btnSelectFeature_Click(object sender, EventArgs e)
  687.         //{
  688.         //    ICommand pCommand = new ControlsSelectFeaturesToolClass();
  689.         //    ITool pTool = pCommand as ITool;
  690.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  691.         //    {
  692.         //        pCommand.OnCreate(this.mainMapControl.Object);
  693.         //        this.mainMapControl.CurrentTool = pTool;
  694.         //    }
  695.         //    else
  696.         //    {
  697.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  698.         //        this.axPageLayoutControl.CurrentTool = pTool;
  699.         //    }
  700.         //}
  701.         //private void btnClearSelect_Click(object sender, EventArgs e)
  702.         //{
  703.         //    ICommand pCommand = new ControlsClearSelectionCommandClass();
  704.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  705.         //    {
  706.         //        pCommand.OnCreate(this.mainMapControl.Object);
  707.         //        pCommand.OnClick();
  708.         //    }
  709.         //    else
  710.         //    {
  711.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  712.         //        pCommand.OnClick();
  713.         //    }
  714.         //}
  715.         //private void btnSelectElement_Click(object sender, EventArgs e)
  716.         //{
  717.         //    ICommand pCommand = new ControlsSelectToolClass();
  718.         //    ITool pTool = pCommand as ITool;
  719.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  720.         //    {
  721.         //        pCommand.OnCreate(this.mainMapControl.Object);
  722.         //        this.mainMapControl.CurrentTool = pTool;
  723.         //    }
  724.         //    else
  725.         //    {
  726.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  727.         //        this.axPageLayoutControl.CurrentTool = pTool;
  728.         //    }
  729.         //}
  730.         //private void btnIdentify_Click(object sender, EventArgs e)
  731.         //{
  732.         //    ICommand pCommand = new ControlsMapIdentifyToolClass();
  733.         //    ITool pTool = pCommand as ITool;
  734.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  735.         //    {
  736.         //        pCommand.OnCreate(this.mainMapControl.Object);
  737.         //        this.mainMapControl.CurrentTool = pTool;
  738.         //    }
  739.         //    else
  740.         //    {
  741.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  742.         //        this.axPageLayoutControl.CurrentTool = pTool;
  743.         //    }
  744.         //}
  745.         //private void btnFind_Click(object sender, EventArgs e)
  746.         //{
  747.         //    ICommand pCommand = new ControlsMapFindCommandClass();
  748.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  749.         //    {
  750.         //        pCommand.OnCreate(this.mainMapControl.Object);
  751.         //        pCommand.OnClick();
  752.         //    }
  753.         //    else
  754.         //    {
  755.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  756.         //        pCommand.OnClick();
  757.         //    }
  758.         //}
  759.         //private void btnGoToXY_Click(object sender, EventArgs e)
  760.         //{
  761.         //    ICommand pCommand = new ControlsMapGoToCommandClass();
  762.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  763.         //    {
  764.         //        pCommand.OnCreate(this.mainMapControl.Object);
  765.         //        pCommand.OnClick();
  766.         //    }
  767.         //    else
  768.         //    {
  769.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  770.         //        pCommand.OnClick();
  771.         //    }
  772.         //}
  773.         //private void btnMeasure_Click(object sender, EventArgs e)
  774.         //{
  775.         //    ICommand pCommand = new ControlsMapMeasureToolClass();
  776.         //    ITool pTool = pCommand as ITool;
  777.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  778.         //    {
  779.         //        pCommand.OnCreate(this.mainMapControl.Object);
  780.         //        this.mainMapControl.CurrentTool = pTool;
  781.         //    }
  782.         //    else
  783.         //    {
  784.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  785.         //        this.axPageLayoutControl.CurrentTool = pTool;
  786.         //    }
  787.         //}
  788.         //private void btnHyperlink_Click(object sender, EventArgs e)
  789.         //{
  790.         //    ICommand pCommand = new ControlsMapHyperlinkToolClass();
  791.         //    ITool pTool = pCommand as ITool;
  792.         //    if (this.tabCtrlDataAndLayout.SelectedTab == this.tpgData)
  793.         //    {
  794.         //        pCommand.OnCreate(this.mainMapControl.Object);
  795.         //        this.mainMapControl.CurrentTool = pTool;
  796.         //    }
  797.         //    else
  798.         //    {
  799.         //        pCommand.OnCreate(this.axPageLayoutControl.Object);
  800.         //        this.axPageLayoutControl.CurrentTool = pTool;
  801.         //    }
  802.         //}
  803.         #endregion
  804.         #region 主窗体Size变化event handler
  805.         private void MainFrm_ResizeBegin(object sender, EventArgs e)
  806.         {
  807.             this.mainMapControl.SuppressResizeDrawing(true, 0);
  808.             this.EagleaxMapControl.SuppressResizeDrawing(true, 0);
  809.             this.axPageLayoutControl.SuppressResizeDrawing(true, 0);
  810.             this.axTOCControl.SetBuddyControl(null);
  811.         }
  812.         private void MainFrm_ResizeEnd(object sender, EventArgs e)
  813.         {
  814.             this.mainMapControl.SuppressResizeDrawing(false, 0);
  815.             this.axPageLayoutControl.SuppressResizeDrawing(false, 0);
  816.             this.EagleaxMapControl.SuppressResizeDrawing(false, 0);
  817.             this.axTOCControl.SetBuddyControl(this.mainMapControl.Object);
  818.         }
  819.         #endregion
  820.         private void btnFlashShape_Click(object sender, EventArgs e)
  821.         {
  822.             //IEnvelope pEnvelope = this.mainMapControl.TrackRectangle();
  823.             //IIdentify2 pIdentify = this.mainMapControl.get_Layer(0) as IIdentify2;
  824.             //IArray pArray = pIdentify.Identify(pEnvelope as IGeometry, null);
  825.             //IIdentifyObj pIdentifyObj;
  826.             //for (int i = 0; i < pArray.Count; i++)
  827.             //{
  828.             //    pIdentifyObj = (IIdentifyObj)pArray.get_Element(i);
  829.             //    pIdentifyObj.Flash(this.mainMapControl.ActiveView.ScreenDisplay);
  830.             //}
  831.             double a = Convert.ToDouble(txtDouble.Text);
  832.             lblDouble.Text = a.ToString(txtFormat.Text);
  833.         }
  834.      
  835.         private void toolStripButton1_Click(object sender, EventArgs e)
  836.         {
  837.             for (int i = 0; i < 12; i++)
  838.             {
  839.                    
  840.             }
  841.         }
  842.         private void toolStripButton2_Click(object sender, EventArgs e)
  843.         {
  844.             ILayer pLayer = this.mainMapControl.Map.get_Layer(0);
  845.             if (pLayer is IFeatureLayer)
  846.             {
  847.                 if (((IFeatureLayer)pLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
  848.                 {
  849.                     IFeatureSelection pFeatureSelection = pLayer as IFeatureSelection;
  850.                     ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet;
  851.                     ICursor pCursor;
  852.                     pSelectionSet.Search(null, false, out pCursor);
  853.                     if (pCursor != null)
  854.                     {
  855.                         IRow pRow = pCursor.NextRow();
  856.                         if (pRow != null)
  857.                         {
  858.                             IArea pArea = ((IFeature)pRow).Shape as IArea;
  859.                             MessageBox.Show(pArea.Area.ToString());
  860.                         }
  861.                     }
  862.                 }
  863.             }
  864.             //ICommand pCommand = new ControlsNewCircleToolClass();
  865.             //pCommand.OnCreate(this.mainMapControl.Object);
  866.             //ITool pTool = pCommand as ITool;
  867.             //this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
  868.             //this.mainMapControl.CurrentTool = pTool;
  869.         }
  870.         private void toolStripButton3_Click(object sender, EventArgs e)
  871.         {
  872.             ICommand pCommand = new ControlsNewMarkerToolClass();
  873.             pCommand.OnCreate(this.mainMapControl.Object);
  874.             ITool pTool = pCommand as ITool;
  875.             this.mainMapControl.CurrentTool = pTool;
  876.             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
  877.         }
  878.         private void toolStripButton4_Click(object sender, EventArgs e)
  879.         {
  880.             ICommand pCommand = new ControlsRotateElementToolClass();
  881.             pCommand.OnCreate(this.mainMapControl.Object);
  882.             ITool pTool = pCommand as ITool;
  883.             this.mainMapControl.CurrentTool = pTool;
  884.         }
  885.         private void toolStripButton5_Click(object sender, EventArgs e)
  886.         {
  887.             ICommand pCommand = new ControlsAlignBottomCommandClass();
  888.             pCommand.OnCreate(this.mainMapControl.Object);
  889.             pCommand.OnClick();
  890.         }
  891.         private void toolStripButton6_Click(object sender, EventArgs e)
  892.         {
  893.             ICommand pCommand = new ControlsGroupCommandClass();
  894.             pCommand.OnCreate(this.mainMapControl.Object);
  895.             pCommand.OnClick();
  896.         }
  897.         private void toolStripButton7_Click(object sender, EventArgs e)
  898.         {
  899.             this.selectionChangedHandler = new IActiveViewEvents_SelectionChangedEventHandler(this.onSelectionChanged);
  900.             this.pMap = this.mainMapControl.ActiveView.FocusMap;
  901.             ((IActiveViewEvents_Event)this.pMap).SelectionChanged += this.selectionChangedHandler;
  902.         }
  903.         private IMap pMap;
  904.         private IActiveViewEvents_SelectionChangedEventHandler selectionChangedHandler;
  905.         private void onSelectionChanged()
  906.         {
  907.             MessageBox.Show("Selection Changed");
  908.         }
  909.         private void mainMapControl_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
  910.         {
  911.             IEnvelope pEnvelope = e.newEnvelope as IEnvelope;
  912.             ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
  913.             pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDash;
  914.             pSimpleLineSymbol.Width = 2;
  915.             pSimpleLineSymbol.Color = this.getRGBColor(0, 0, 0);
  916.             ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
  917.             pSimpleFillSymbol.Color = this.getRGBColor(255, 0, 0);
  918.             pSimpleFillSymbol.Outline = pSimpleLineSymbol as ILineSymbol;
  919.             pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
  920.             IRectangleElement pRectangleElement = new RectangleElementClass();
  921.             IElement pElement = pRectangleElement as IElement;
  922.             pElement.Geometry = pEnvelope as IGeometry;
  923.             IFillShapeElement pFillShapeElement = pRectangleElement as IFillShapeElement;
  924.             pFillShapeElement.Symbol = pSimpleFillSymbol as IFillSymbol;
  925.             IGraphicsContainer pGraphicsContainer = this.EagleaxMapControl.Map as IGraphicsContainer;
  926.             pGraphicsContainer.DeleteAllElements();
  927.             pGraphicsContainer.AddElement(pElement, 0);
  928.             this.EagleaxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
  929.         }
  930.         private void EagleaxMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
  931.         {
  932.             if (this.EagleaxMapControl.Map.LayerCount != 0)
  933.             {
  934.                 if (e.button == 1)
  935.                 {
  936.                     IPoint pPoint = new PointClass();
  937.                     pPoint.PutCoords(e.mapX, e.mapY);
  938.                     IEnvelope pEnvelope = this.mainMapControl.Extent;
  939.                     pEnvelope.CenterAt(pPoint);
  940.                     this.mainMapControl.Extent = pEnvelope;
  941.                     this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  942.                 }
  943.                 else if (e.button == 2)
  944.                 {
  945.                     IEnvelope pEnvelop = this.EagleaxMapControl.TrackRectangle();
  946.                     this.mainMapControl.Extent = pEnvelop;
  947.                     this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  948.                 }
  949.             }
  950.         }
  951.         private void EagleaxMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
  952.         {
  953.             if (e.button != 1) return;
  954.             IPoint pPoint = new PointClass();
  955.             pPoint.PutCoords(e.mapX, e.mapY);
  956.             this.mainMapControl.CenterAt(pPoint);
  957.             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  958.         }
  959.         private void mainMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
  960.         {
  961.             //this.lblCurrentLocation.Text = string.Format("{0},{1},{2}", e.mapX.ToString("#######.###"), e.mapY.ToString("#######.###"), this.mainMapControl.MapUnits.ToString().Substring(4));
  962.             this.lblCurrentLocation.Text = string.Format("{0}  {1}  {2}", e.mapX.ToString("#######.###"), e.mapY.ToString("#######.###"), this.mainMapControl.MapUnits.ToString().Substring(4));
  963.         }
  964.         private void axPageLayoutControl_OnMouseMove(object sender, IPageLayoutControlEvents_OnMouseMoveEvent e)
  965.         {
  966.             //this.lblCurrentLocation.Text = string.Format("{0},{1},{2}", e.pageX.ToString("#######.###"), e.pageY.ToString("#######.###"), this.axPageLayoutControl.Page.Units.ToString().Substring(4));
  967.             this.lblCurrentLocation.Text = string.Format("{0}  {1}  {2}", e.pageX.ToString("#######.###"), e.pageY.ToString("#######.###"), this.axPageLayoutControl.Page.Units.ToString().Substring(4));
  968.         }
  969.         private void SaveDocToolStripMenuItem_Click(object sender, EventArgs e)
  970.         {
  971.             try
  972.             {
  973.                 if (this.pMapDocument != null)
  974.                 {
  975.                     this.pMapDocument.Save(this.pMapDocument.UsesRelativePaths, true);
  976.                 }
  977.                 else
  978.                 {
  979.                     this.SaveDocAsToolStripMenuItem_Click(null, null);
  980.                 }
  981.             }
  982.             catch (Exception ex)
  983.             {
  984.                 MessageBox.Show(ex.Message);
  985.             }
  986.         }
  987.         private void SaveDocAsToolStripMenuItem_Click(object sender, EventArgs e)
  988.         {
  989.             try
  990.             {
  991.                 this.pMapDocument = new MapDocumentClass();
  992.                 this.saveFileDialog.Filter = "MXD文件|*.mxd";
  993.                 if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
  994.                 {
  995.                     this.pMapDocument.New(this.saveFileDialog.FileName);
  996.                     IMxdContents pMxdContents = this.m_controlsSynchronizer as IMxdContents;
  997.                     this.pMapDocument.ReplaceContents(pMxdContents);
  998.                     this.pMapDocument.Save(true, true);
  999.                 }
  1000.             }
  1001.             catch (Exception ex)
  1002.             {
  1003.                 MessageBox.Show(ex.Message);
  1004.             }
  1005.         }
  1006.         private void NewToolStripMenuItem_Click(object sender, EventArgs e)
  1007.         {
  1008.         }
  1009.         private void toolStripButton2_Click_1(object sender, EventArgs e)
  1010.         {
  1011.             this.barToc.Hide();
  1012.         }
  1013.         private void toolStripButton3_Click_1(object sender, EventArgs e)
  1014.         {
  1015.             //this.barEagelMap.ReDock();
  1016.         }
  1017.         private void tabCtrlDataAndLayout_SelectedIndexChanged_1(object sender, EventArgs e)
  1018.         {
  1019.         }
  1020.         private void tabControl_SelectedTabChanged(object sender, DevComponents.DotNetBar.TabStripTabChangedEventArgs e)
  1021.         {
  1022.             if (this.tabControl.SelectedTabIndex == 0)
  1023.             {
  1024.                 //activate the MapControl and deactivate the PageLayoutControl
  1025.                 m_controlsSynchronizer.ActivateMap();
  1026.             }
  1027.             else
  1028.             {
  1029.                 //activate the PageLayoutControl and deactivate the MapControl
  1030.                 m_controlsSynchronizer.ActivatePageLayout();
  1031.             }
  1032.         }
  1033.         #region 泡泡工具条之地图浏览
  1034.         private void bubbleBtnMapZoomIn_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1035.         {
  1036.             ICommand pCommand = new ControlsMapZoomInToolClass();
  1037.             ITool pTool = pCommand as ITool;
  1038.             switch (this.tabControl.SelectedTabIndex)
  1039.             {
  1040.                 case 0:
  1041.                     pCommand.OnCreate(this.mainMapControl.Object);
  1042.                     this.mainMapControl.CurrentTool = pTool;
  1043.                     break;
  1044.                 case 1:
  1045.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1046.                     this.axPageLayoutControl.CurrentTool = pTool;
  1047.                     break;
  1048.             }
  1049.         }
  1050.         private void bubbleBtnMapZoomOut_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1051.         {
  1052.             ICommand pCommand = new ControlsMapZoomOutToolClass();
  1053.             ITool pTool = pCommand as ITool;
  1054.             switch (this.tabControl.SelectedTabIndex)
  1055.             {
  1056.                 case 0:
  1057.                     pCommand.OnCreate(this.mainMapControl.Object);
  1058.                     this.mainMapControl.CurrentTool = pTool;
  1059.                     break;
  1060.                 case 1:
  1061.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1062.                     this.axPageLayoutControl.CurrentTool = pTool;
  1063.                     break;
  1064.             }
  1065.         }
  1066.         private void bubbleBtnPan_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1067.         {
  1068.             ICommand pCommand = new ControlsMapPanToolClass();
  1069.             ITool pTool = pCommand as ITool;
  1070.             switch (this.tabControl.SelectedTabIndex)
  1071.             {
  1072.                 case 0:
  1073.                     pCommand.OnCreate(this.mainMapControl.Object);
  1074.                     this.mainMapControl.CurrentTool = pTool;
  1075.                     break;
  1076.                 case 1:
  1077.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1078.                     this.axPageLayoutControl.CurrentTool = pTool;
  1079.                     break;
  1080.             }
  1081.         }
  1082.         private void bubbleBtnSelectFeature_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1083.         {
  1084.             ICommand pCommand = new ControlsSelectFeaturesToolClass();
  1085.             ITool pTool = pCommand as ITool;
  1086.             switch (this.tabControl.SelectedTabIndex)
  1087.             {
  1088.                 case 0:
  1089.                     pCommand.OnCreate(this.mainMapControl.Object);
  1090.                     this.mainMapControl.CurrentTool = pTool;
  1091.                     break;
  1092.                 case 1:
  1093.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1094.                     this.axPageLayoutControl.CurrentTool = pTool;
  1095.                     break;
  1096.             }
  1097.         }
  1098.         private void bubbleBtnSelectElement_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1099.         {
  1100.             ICommand pCommand = new ControlsSelectToolClass();
  1101.             ITool pTool = pCommand as ITool;
  1102.             switch (this.tabControl.SelectedTabIndex)
  1103.             {
  1104.                 case 0:
  1105.                     pCommand.OnCreate(this.mainMapControl.Object);
  1106.                     this.mainMapControl.CurrentTool = pTool;
  1107.                     break;
  1108.                 case 1:
  1109.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1110.                     this.axPageLayoutControl.CurrentTool = pTool;
  1111.                     break;
  1112.             }
  1113.         }
  1114.         private void bubbleBtnIdentify_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1115.         {
  1116.             ICommand pCommand = new ControlsMapIdentifyToolClass();
  1117.             ITool pTool = pCommand as ITool;
  1118.             switch (this.tabControl.SelectedTabIndex)
  1119.             {
  1120.                 case 0:
  1121.                     pCommand.OnCreate(this.mainMapControl.Object);
  1122.                     this.mainMapControl.CurrentTool = pTool;
  1123.                     break;
  1124.                 case 1:
  1125.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1126.                     this.axPageLayoutControl.CurrentTool = pTool;
  1127.                     break;
  1128.             }
  1129.         }
  1130.         private void bubbleBtnMeasure_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1131.         {
  1132.             ICommand pCommand = new ControlsMapMeasureToolClass();
  1133.             ITool pTool = pCommand as ITool;
  1134.             switch (this.tabControl.SelectedTabIndex)
  1135.             {
  1136.                 case 0:
  1137.                     pCommand.OnCreate(this.mainMapControl.Object);
  1138.                     this.mainMapControl.CurrentTool = pTool;
  1139.                     break;
  1140.                 case 1:
  1141.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1142.                     this.axPageLayoutControl.CurrentTool = pTool;
  1143.                     break;
  1144.             }
  1145.         }
  1146.         private void bubbleBtnFullExtent_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1147.         {
  1148.             ICommand pCommand = new ControlsMapFullExtentCommandClass();
  1149.             pCommand.OnCreate(this.mainMapControl.Object);
  1150.             pCommand.OnClick();
  1151.         }
  1152.         private void bubbleBtnMapFixedZoomIn_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1153.         {
  1154.             ICommand pCommand = new ControlsMapZoomInFixedCommandClass();
  1155.             pCommand.OnCreate(this.mainMapControl.Object);
  1156.             pCommand.OnClick();
  1157.         }
  1158.         private void bubbleBtnFixedZoomOut_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1159.         {
  1160.             ICommand pCommand = new ControlsMapZoomOutFixedCommandClass();
  1161.             pCommand.OnCreate(this.mainMapControl.Object);
  1162.             pCommand.OnClick();
  1163.         }
  1164.         private void bubbleBtnPreExtent_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1165.         {
  1166.             ICommand pCommand = new ControlsMapZoomToLastExtentBackCommandClass();
  1167.             pCommand.OnCreate(this.mainMapControl.Object);
  1168.             pCommand.OnClick();
  1169.         }
  1170.         private void bubbleBtnNextExtent_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1171.         {
  1172.             ICommand pCommand = new ControlsMapZoomToLastExtentForwardCommandClass();
  1173.             pCommand.OnCreate(this.mainMapControl.Object);
  1174.             pCommand.OnClick();
  1175.         }
  1176.         private void bubbleBtnClearSelection_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1177.         {
  1178.             ICommand pCommand = new ControlsClearSelectionCommandClass();
  1179.             pCommand.OnCreate(this.mainMapControl.Object);
  1180.             pCommand.OnClick();
  1181.         }
  1182.         private void bubbleBtnFind_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1183.         {
  1184.             ICommand pCommand = new ControlsMapFindCommandClass();
  1185.             pCommand.OnCreate(this.mainMapControl.Object);
  1186.             pCommand.OnClick();
  1187.         }
  1188.         private void bubbleBtnGotoXY_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1189.         {
  1190.             ICommand pCommand = new ControlsMapGoToCommandClass();
  1191.             pCommand.OnCreate(this.mainMapControl.Object);
  1192.             pCommand.OnClick();
  1193.         }
  1194.         #endregion 泡泡工具条之地图浏览
  1195.         private void btnNewDoc_Click(object sender, EventArgs e)
  1196.         {
  1197.             if (this.mainMapControl.LayerCount > 0)
  1198.             {
  1199.                 DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  1200.                 if (result == DialogResult.Cancel) return;
  1201.                 if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null);
  1202.             }
  1203.             this.mainMapControl.Map = new MapClass();
  1204.             this.mainMapControl.DocumentFilename = "";
  1205.             this.m_controlsSynchronizer.ReplaceMap(this.mainMapControl.Map);
  1206.             this.Text = "LinGIS - LinInfo";
  1207.         }
  1208.         private void btnSaveDoc_Click(object sender, EventArgs e)
  1209.         {
  1210.             if (this.mainMapControl.DocumentFilename != "")
  1211.             {
  1212.                 try
  1213.                 {
  1214.                     this.pMapDocument = new MapDocumentClass();
  1215.                     this.pMapDocument.Open(this.mainMapControl.DocumentFilename,"");
  1216.                     this.pMapDocument.ReplaceContents((IMxdContents)this.mainMapControl.Map);
  1217.                     this.pMapDocument.ReplaceContents((IMxdContents)this.axPageLayoutControl.PageLayout);
  1218.                     this.pMapDocument.Save(true, false);
  1219.                 }
  1220.                 catch (Exception ex)
  1221.                 {
  1222.                     MessageBox.Show(ex.Message);
  1223.                 }
  1224.                 finally
  1225.                 {
  1226.                     System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument);
  1227.                     Application.DoEvents();
  1228.                     this.pMapDocument = null;
  1229.                 }
  1230.             }
  1231.             else
  1232.             {
  1233.                 this.btnSaveDocAs_Click(null, null);
  1234.             }
  1235.         }
  1236.         private void btnSaveDocAs_Click(object sender, EventArgs e)
  1237.         {
  1238.             this.saveFileDialog.Filter = "MXD地图文档(*.mxd)|*.mxd";
  1239.             if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
  1240.             {
  1241.                 try
  1242.                 {
  1243.                     this.pMapDocument = new MapDocumentClass();
  1244.                     this.pMapDocument.New(this.saveFileDialog.FileName);
  1245.                     this.pMapDocument.ReplaceContents((IMxdContents)this.mainMapControl.Map);
  1246.                     this.pMapDocument.ReplaceContents((IMxdContents)this.axPageLayoutControl.PageLayout);
  1247.                     this.pMapDocument.Save(true, false);
  1248.                     this.mainMapControl.DocumentFilename = this.saveFileDialog.FileName;
  1249.                     this.Text = System.IO.Path.GetFileName(this.saveFileDialog.FileName) + " - " + "LinGIS - LinInfo";
  1250.                 }
  1251.                 catch (Exception ex)
  1252.                 {
  1253.                     MessageBox.Show(ex.Message);
  1254.                 }
  1255.                 finally
  1256.                 {
  1257.                     System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument);
  1258.                     Application.DoEvents();
  1259.                     this.pMapDocument = null;
  1260.                 }
  1261.             }
  1262.         }
  1263.         private void btnOpenDoc_Click(object sender, EventArgs e)
  1264.         {
  1265.             if (this.mainMapControl.LayerCount > 0)
  1266.             {
  1267.                 DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  1268.                 if (result == DialogResult.Cancel) return;
  1269.                 if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null);
  1270.             }
  1271.             this.openFileDialog.Title = "请选择地图文件";
  1272.             this.openFileDialog.Filter = "MXD地图文件|*.mxd";
  1273.             this.openFileDialog.Multiselect = false;
  1274.             this.openFileDialog.RestoreDirectory = true;
  1275.             if (this.openFileDialog.ShowDialog() == DialogResult.OK)
  1276.             {
  1277.                 Application.DoEvents();
  1278.                 string docName = this.openFileDialog.FileName;
  1279.                 try
  1280.                 {
  1281.                     this.pMapDocument = new MapDocumentClass();
  1282.                     if (pMapDocument.get_IsPresent(docName) && !pMapDocument.get_IsPasswordProtected(docName))
  1283.                     {
  1284.                         pMapDocument.Open(docName, null);
  1285.                         IMap pMap = pMapDocument.get_Map(0);
  1286.                         m_controlsSynchronizer.ReplaceMap(pMap);
  1287.                         this.mainMapControl.DocumentFilename = docName;
  1288.                         this.Text = System.IO.Path.GetFileName(this.openFileDialog.FileName) + " - " + "LinGIS - LinInfo";
  1289.                     }
  1290.                 }
  1291.                 catch (Exception ex)
  1292.                 {
  1293.                     MessageBox.Show(ex.Message);
  1294.                 }
  1295.                 finally
  1296.                 {
  1297.                     System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument);
  1298.                     Application.DoEvents();
  1299.                     this.pMapDocument = null;
  1300.                 }
  1301.             }
  1302.         }
  1303.         private void btnAddData_Click(object sender, EventArgs e)
  1304.         {
  1305.             int currentLayerCount = this.mainMapControl.LayerCount;
  1306.             
  1307.             ICommand pCommand = new ControlsAddDataCommandClass();
  1308.             pCommand.OnCreate(this.mainMapControl.Object);
  1309.             pCommand.OnClick();
  1310.             IMap pMap = this.mainMapControl.Map;
  1311.             this.m_controlsSynchronizer.ReplaceMap(pMap);
  1312.             if (this.mainMapControl.LayerCount > currentLayerCount)
  1313.             {
  1314.                 this.EagleaxMapControl.AddLayer(this.mainMapControl.get_Layer(0));
  1315.                 this.EagleaxMapControl.Extent = this.EagleaxMapControl.FullExtent;
  1316.                 this.EagleaxMapControl.Refresh();
  1317.             }
  1318.         }
  1319.         private void bubbleBtnNewDoc_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1320.         {
  1321.             this.btnNewDoc_Click(sender, e as EventArgs);
  1322.         }
  1323.         private void bubbleBtnOpenDoc_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1324.         {
  1325.             this.btnOpenDoc_Click(sender, e as EventArgs);
  1326.         }
  1327.         private void bubbleBtnAddData_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1328.         {
  1329.             this.btnAddData_Click(sender, e);
  1330.         }
  1331.         private void btnExitApplication_Click(object sender, EventArgs e)
  1332.         {
  1333.             if (this.mainMapControl.LayerCount > 0)
  1334.             {
  1335.                 DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  1336.                 if (result == DialogResult.Cancel) return;
  1337.                 if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null);
  1338.             }
  1339.             Application.Exit();
  1340.         }
  1341.         #region 绘制元素工具条
  1342.         private void btnDrawSelectElement_Click(object sender, EventArgs e)
  1343.         {
  1344.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1345.             ICommand pCommand = new ControlsSelectToolClass();
  1346.             ITool pTool = pCommand as ITool;
  1347.             switch (this.tabControl.SelectedTabIndex)
  1348.             {
  1349.                 case 0:
  1350.                     pCommand.OnCreate(this.mainMapControl.Object);
  1351.                     this.mainMapControl.CurrentTool = pTool;
  1352.                     break;
  1353.                 case 1:
  1354.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1355.                     this.axPageLayoutControl.CurrentTool = pTool;
  1356.                     break;
  1357.             }
  1358.         }
  1359.         private void btnDrawNewRenctangle_Click(object sender, EventArgs e)
  1360.         {
  1361.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1362.             ICommand pCommand = new ControlsNewRectangleToolClass();
  1363.             ITool pTool = pCommand as ITool;
  1364.             switch (this.tabControl.SelectedTabIndex)
  1365.             {
  1366.                 case 0:
  1367.                     pCommand.OnCreate(this.mainMapControl.Object);
  1368.                     this.mainMapControl.CurrentTool = pTool;
  1369.                     break;
  1370.                 case 1:
  1371.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1372.                     this.axPageLayoutControl.CurrentTool = pTool;
  1373.                     break;
  1374.             }
  1375.         }
  1376.         private void btnDrawNewPolygon_Click(object sender, EventArgs e)
  1377.         {
  1378.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1379.             ICommand pCommand = new ControlsNewPolygonToolClass();
  1380.             ITool pTool = pCommand as ITool;
  1381.             switch (this.tabControl.SelectedTabIndex)
  1382.             {
  1383.                 case 0:
  1384.                     pCommand.OnCreate(this.mainMapControl.Object);
  1385.                     this.mainMapControl.CurrentTool = pTool;
  1386.                     break;
  1387.                 case 1:
  1388.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1389.                     this.axPageLayoutControl.CurrentTool = pTool;
  1390.                     break;
  1391.             }
  1392.         }
  1393.         private void btnDrawNewCircle_Click(object sender, EventArgs e)
  1394.         {
  1395.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1396.             ICommand pCommand = new ControlsNewCircleToolClass();
  1397.             ITool pTool = pCommand as ITool;
  1398.             switch (this.tabControl.SelectedTabIndex)
  1399.             {
  1400.                 case 0:
  1401.                     pCommand.OnCreate(this.mainMapControl.Object);
  1402.                     this.mainMapControl.CurrentTool = pTool;
  1403.                     break;
  1404.                 case 1:
  1405.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1406.                     this.axPageLayoutControl.CurrentTool = pTool;
  1407.                     break;
  1408.             }
  1409.         }
  1410.         private void btnDrawNewEllipse_Click(object sender, EventArgs e)
  1411.         {
  1412.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1413.             ICommand pCommand = new ControlsNewEllipseToolClass();
  1414.             ITool pTool = pCommand as ITool;
  1415.             switch (this.tabControl.SelectedTabIndex)
  1416.             {
  1417.                 case 0:
  1418.                     pCommand.OnCreate(this.mainMapControl.Object);
  1419.                     this.mainMapControl.CurrentTool = pTool;
  1420.                     break;
  1421.                 case 1:
  1422.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1423.                     this.axPageLayoutControl.CurrentTool = pTool;
  1424.                     break;
  1425.             }
  1426.         }
  1427.         private void btnDrawNewLine_Click(object sender, EventArgs e)
  1428.         {
  1429.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1430.             ICommand pCommand = new ControlsNewLineToolClass();
  1431.             ITool pTool = pCommand as ITool;
  1432.             switch (this.tabControl.SelectedTabIndex)
  1433.             {
  1434.                 case 0:
  1435.                     pCommand.OnCreate(this.mainMapControl.Object);
  1436.                     this.mainMapControl.CurrentTool = pTool;
  1437.                     break;
  1438.                 case 1:
  1439.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1440.                     this.axPageLayoutControl.CurrentTool = pTool;
  1441.                     break;
  1442.             }
  1443.         }
  1444.         private void btnDrawNewCurve_Click(object sender, EventArgs e)
  1445.         {
  1446.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1447.             ICommand pCommand = new ControlsNewCurveToolClass();
  1448.             ITool pTool = pCommand as ITool;
  1449.             switch (this.tabControl.SelectedTabIndex)
  1450.             {
  1451.                 case 0:
  1452.                     pCommand.OnCreate(this.mainMapControl.Object);
  1453.                     this.mainMapControl.CurrentTool = pTool;
  1454.                     break;
  1455.                 case 1:
  1456.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1457.                     this.axPageLayoutControl.CurrentTool = pTool;
  1458.                     break;
  1459.             }
  1460.         }
  1461.         private void btnDrawNewFreeHand_Click(object sender, EventArgs e)
  1462.         {
  1463.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1464.             ICommand pCommand = new ControlsNewFreeHandToolClass();
  1465.             ITool pTool = pCommand as ITool;
  1466.             switch (this.tabControl.SelectedTabIndex)
  1467.             {
  1468.                 case 0:
  1469.                     pCommand.OnCreate(this.mainMapControl.Object);
  1470.                     this.mainMapControl.CurrentTool = pTool;
  1471.                     break;
  1472.                 case 1:
  1473.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1474.                     this.axPageLayoutControl.CurrentTool = pTool;
  1475.                     break;
  1476.             }
  1477.         }
  1478.         private void btnDrawNewMarker_Click(object sender, EventArgs e)
  1479.         {
  1480.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1481.             ICommand pCommand = new ControlsNewMarkerToolClass();
  1482.             ITool pTool = pCommand as ITool;
  1483.             switch (this.tabControl.SelectedTabIndex)
  1484.             {
  1485.                 case 0:
  1486.                     pCommand.OnCreate(this.mainMapControl.Object);
  1487.                     this.mainMapControl.CurrentTool = pTool;
  1488.                     break;
  1489.                 case 1:
  1490.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1491.                     this.axPageLayoutControl.CurrentTool = pTool;
  1492.                     break;
  1493.             }
  1494.         }
  1495.         #endregion
  1496.         private void buttonItemSelectFeature_Click(object sender, EventArgs e)
  1497.         {
  1498.             ICommand pCommand = new ControlsSelectFeaturesToolClass();
  1499.             ITool pTool = pCommand as ITool;
  1500.             switch (this.tabControl.SelectedTabIndex)
  1501.             {
  1502.                 case 0:
  1503.                     pCommand.OnCreate(this.mainMapControl.Object);
  1504.                     this.mainMapControl.CurrentTool = pTool;
  1505.                     break;
  1506.                 case 1:
  1507.                     pCommand.OnCreate(this.axPageLayoutControl.Object);
  1508.                     this.axPageLayoutControl.CurrentTool = pTool;
  1509.                     break;
  1510.             }
  1511.         }
  1512.         
  1513.         private void btnSelectByAttr_Click(object sender, EventArgs e)
  1514.         {
  1515.             SelectByAttrFrm newSelectByAttrFrm = new SelectByAttrFrm(this);
  1516.             newSelectByAttrFrm.Show((IWin32Window)this);
  1517.         }
  1518.         private IPoint mapRightClickPoint;
  1519.         private IPoint mapTextPoint;
  1520.         private void mainMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
  1521.         {
  1522.             if (e.button == 2)
  1523.             {
  1524.                 if (this.mapRightClickPoint == null)
  1525.                 {
  1526.                     this.mapRightClickPoint = new PointClass();
  1527.                 }
  1528.                 this.mapRightClickPoint.PutCoords(e.mapX, e.mapY);
  1529.                 IGraphicsContainer pGraphicContainer = this.mainMapControl.Map as IGraphicsContainer;
  1530.                 IEnumElement pEnumElement = pGraphicContainer.LocateElements(this.mapRightClickPoint, this.mainMapControl.ActiveView.Extent.Width / 500);
  1531.                 if (pEnumElement != null)
  1532.                 {
  1533.                     return;
  1534.                 }
  1535.                 else
  1536.                 {
  1537.                     this.contextMenuMapNormal.Show(this.mainMapControl as Control, new System.Drawing.Point(e.x, e.y));
  1538.                 }
  1539.             }
  1540.             else if (e.button == 1)
  1541.             {
  1542.                 if (this.btnDrawNewText.Checked == false) return;
  1543.                 
  1544.                 if (this.mapTextPoint == null)
  1545.                 {
  1546.                     this.mapTextPoint = new PointClass();
  1547.                 }
  1548.                 this.mapTextPoint.PutCoords(e.mapX, e.mapY);
  1549.                 this.txtNewText.Location = new System.Drawing.Point(e.x, e.y);
  1550.                 this.txtNewText.Text = "文本";
  1551.                 this.txtNewText.Visible = true;
  1552.                 this.txtNewText.Focus();
  1553.                 this.txtNewText.SelectAll();
  1554.                 this.btnDrawNewText.Checked = false;
  1555.             }
  1556.         }
  1557.         #region MapControl普通右键菜单
  1558.         //全图
  1559.         private void ctMenuMNFullExtent_Click(object sender, EventArgs e)
  1560.         {
  1561.             ICommand pCommand = new ControlsMapFullExtentCommandClass();
  1562.             pCommand.OnCreate(this.mainMapControl.Object);
  1563.             pCommand.OnClick();
  1564.         }
  1565.         //前一视图
  1566.         private void ctMenuMNPreviousExtent_Click(object sender, EventArgs e)
  1567.         {
  1568.             ICommand pCommand = new ControlsMapZoomToLastExtentBackCommandClass();
  1569.             pCommand.OnCreate(this.mainMapControl.Object);
  1570.             pCommand.OnClick();
  1571.         }
  1572.         //下一视图
  1573.         private void ctMenuMNNextExtent_Click(object sender, EventArgs e)
  1574.         {
  1575.             ICommand pCommand = new ControlsMapZoomToLastExtentForwardCommandClass();
  1576.             pCommand.OnCreate(this.mainMapControl.Object);
  1577.             pCommand.OnClick();
  1578.         }
  1579.         //局部放大
  1580.         private void ctMenuMNFixedZoomIn_Click(object sender, EventArgs e)
  1581.         {
  1582.             ICommand pCommand = new ControlsMapZoomInFixedCommandClass();
  1583.             pCommand.OnCreate(this.mainMapControl.Object);
  1584.             pCommand.OnClick();
  1585.         }
  1586.         //局部缩小
  1587.         private void ctMenuMNFixedZoomOut_Click(object sender, EventArgs e)
  1588.         {
  1589.             ICommand pCommand = new ControlsMapZoomOutFixedCommandClass();
  1590.             pCommand.OnCreate(this.mainMapControl.Object);
  1591.             pCommand.OnClick();
  1592.         }
  1593.         //选择要素
  1594.         private void ctMenuMNSelectFeature_Click(object sender, EventArgs e)
  1595.         {
  1596.             IMap pMap = this.mainMapControl.Map;
  1597.             ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass();
  1598.             pSelectionEnvironment.LinearSearchDistance = this.mainMapControl.ActiveView.Extent.Width / 200;
  1599.             pSelectionEnvironment.PointSearchDistance = this.mainMapControl.ActiveView.Extent.Width / 200;
  1600.             pMap.SelectByShape(this.mapRightClickPoint as IGeometry, null, false);
  1601.             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
  1602.         }
  1603.         //识别
  1604.         private void ctMenuMNFIdentify_Click(object sender, EventArgs e)
  1605.         {
  1606.         }
  1607.         
  1608.         //居中
  1609.         private void ctMenuMNCenter_Click(object sender, EventArgs e)
  1610.         {
  1611.             this.mainMapControl.CenterAt(this.mapRightClickPoint);
  1612.         }
  1613.         #endregion MapControl普通右键菜单
  1614.         private void bubbleBtnAddCAD_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1615.         {
  1616.             this.openFileDialog.Filter = "DWG文件|*.dwg";
  1617.             this.openFileDialog.Title = "请选择CAD文件";
  1618.             if (this.openFileDialog.ShowDialog() == DialogResult.OK)
  1619.             {
  1620.                 string dirction = System.IO.Path.GetDirectoryName(this.openFileDialog.FileName);
  1621.                 //MessageBox.Show(System.IO.Path.GetDirectoryName(this.openFileDialog.FileName) + "n" +
  1622.                 //                System.IO.Path.GetFileName(this.openFileDialog.FileName) + "n" +
  1623.                 //                System.IO.Path.GetFullPath(this.openFileDialog.FileName));
  1624.                 string file = System.IO.Path.GetFileName(this.openFileDialog.FileName);
  1625.                 IWorkspaceFactory pWorkspaceFatory = new CadWorkspaceFactoryClass();
  1626.                 IWorkspace pWorkspace = pWorkspaceFatory.OpenFromFile(dirction, 0);
  1627.                 IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
  1628.                 IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(file);
  1629.                 IFeatureClassContainer pFeatureClassContainer = pFeatureDataset as IFeatureClassContainer;
  1630.                 IFeatureClass pFeatureClass;
  1631.                 IFeatureLayer pFeatureLayer;
  1632.                 //for (int i = 0; i < pFeatureClassContainer.ClassCount; i++)
  1633.                 //{
  1634.                 //    pFeatureClass = pFeatureClassContainer.get_ClassByID(i);
  1635.                 //    if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
  1636.                 //    {
  1637.                 //        pFeatureLayer = new CadAnnotationLayerClass();
  1638.                 //    }
  1639.                 //    else
  1640.                 //    {
  1641.                 //        pFeatureLayer = new FeatureLayerClass();
  1642.                 //    }
  1643.                 //    pFeatureLayer.Name = pFeatureClass.AliasName;
  1644.                 //    pFeatureLayer.FeatureClass = pFeatureClass;
  1645.                 //    this.mainMapControl.AddLayer(pFeatureLayer as ILayer);
  1646.                 //    this.EagleaxMapControl.AddLayer(pFeatureLayer as ILayer);
  1647.                 //}
  1648.                 IEnumFeatureClass pEnumFeatureClass = pFeatureClassContainer.Classes;
  1649.                 pEnumFeatureClass.Reset();
  1650.                 for (pFeatureClass = pEnumFeatureClass.Next(); pFeatureClass != null; pFeatureClass = pEnumFeatureClass.Next())
  1651.                 {
  1652.                     if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
  1653.                     {
  1654.                         pFeatureLayer = new CadAnnotationLayerClass();
  1655.                     }
  1656.                     else
  1657.                     {
  1658.                         pFeatureLayer = new FeatureLayerClass();
  1659.                     }
  1660.                     pFeatureLayer.Name = pFeatureClass.AliasName;
  1661.                     pFeatureLayer.FeatureClass = pFeatureClass;
  1662.                     this.mainMapControl.AddLayer(pFeatureLayer as ILayer);
  1663.                     this.EagleaxMapControl.AddLayer(pFeatureLayer as ILayer);
  1664.                 }
  1665.                 this.m_controlsSynchronizer.ReplaceMap(this.mainMapControl.Map);
  1666.                 this.EagleaxMapControl.Extent = this.EagleaxMapControl.FullExtent;
  1667.                 this.EagleaxMapControl.Refresh();
  1668.             }
  1669.         }
  1670.         private void ctMenuTFRemove_Click(object sender, EventArgs e)
  1671.         {
  1672.             this.mainMapControl.Map.DeleteLayer(this.TOCRightLayer);
  1673.             this.m_controlsSynchronizer.ReplaceMap(this.mainMapControl.Map);
  1674.             this.EagleaxMapControl.Map.DeleteLayer(this.TOCRightLayer);
  1675.             this.EagleaxMapControl.Extent = this.EagleaxMapControl.FullExtent;
  1676.             this.EagleaxMapControl.Refresh();
  1677.         }
  1678.         private void ctMenuTFZoomToLayer_Click(object sender, EventArgs e)
  1679.         {
  1680.             IFeatureClass pFeatureClass = ((IFeatureLayer)this.TOCRightLayer).FeatureClass;
  1681.             IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
  1682.             this.mainMapControl.Extent = pGeoDataset.Extent;
  1683.             this.mainMapControl.Refresh();
  1684.         }
  1685.         private void ctMenuTFProperties_Click(object sender, EventArgs e)
  1686.         {
  1687.             if (this.newFeatLyrFrm == null)
  1688.             {
  1689.                 this.newFeatLyrFrm = new FeatLyrFrm();
  1690.             }
  1691.             this.newFeatLyrFrm.Layer = this.TOCRightLayer;
  1692.             if (this.newFeatLyrFrm.ShowDialog() == DialogResult.OK)
  1693.             {
  1694.                 this.mainMapControl.Refresh();
  1695.                 this.EagleaxMapControl.Refresh();
  1696.                 this.axTOCControl.Update();
  1697.             }
  1698.         }
  1699.         private void contextMenuTOCFeatureLyr_Opening(object sender, CancelEventArgs e)
  1700.         {
  1701.             if (this.TOCRightLayer is IGeoFeatureLayer)
  1702.             {
  1703.                 this.ctMenuTFProperties.Enabled = true;
  1704.             }
  1705.             else
  1706.             {
  1707.                 this.ctMenuTFProperties.Enabled = false;
  1708.             }
  1709.         }
  1710.         //private void buttonItemSelectFeature_Click(object sender, EventArgs e)
  1711.         //{
  1712.         //    ICommand pCommand = new ControlsSelectToolClass();
  1713.         //    ITool pTool = pCommand as ITool;
  1714.         //    switch (this.tabControl.SelectedTabIndex)
  1715.         //    {
  1716.         //        case 0:
  1717.         //            pCommand.OnCreate(this.mainMapControl.Object);
  1718.         //            this.mainMapControl.CurrentTool = pTool;
  1719.         //            break;
  1720.         //        case 1:
  1721.         //            pCommand.OnCreate(this.axPageLayoutControl.Object);
  1722.         //            this.axPageLayoutControl.CurrentTool = pTool;
  1723.         //            break;
  1724.         //    }
  1725.         //}
  1726.         private void btnClearSelction_Click(object sender, EventArgs e)
  1727.         {
  1728.             this.mainMapControl.Map.ClearSelection();
  1729.             this.mainMapControl.Refresh();
  1730.             this.EagleaxMapControl.Refresh();
  1731.             
  1732.         }
  1733.         private void ctMenuSaveAsLyr_Click(object sender, EventArgs e)
  1734.         {
  1735.             this.saveFileDialog.Title = "保存为Lyr文件";
  1736.             this.saveFileDialog.Filter = "Lyr文件|*.lyr";
  1737.             if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
  1738.             {
  1739.                 string direction = System.IO.Path.GetDirectoryName(this.saveFileDialog.FileName);
  1740.                 string file = System.IO.Path.GetFileName(this.saveFileDialog.FileName);
  1741.                 ILayerFile pLayerFile = new LayerFileClass();
  1742.                 pLayerFile.New(this.saveFileDialog.FileName);
  1743.                 pLayerFile.ReplaceContents(this.TOCRightLayer);
  1744.                 pLayerFile.Save();
  1745.             }
  1746.         }
  1747.         private void ctMenwMapCollapseAll_Click(object sender, EventArgs e)
  1748.         {
  1749.             IEnumLayer pEnumLayer = this.mainMapControl.Map.get_Layers(null, false);
  1750.             if (pEnumLayer == null) return;
  1751.             ILayer pLayer;
  1752.             ILegendInfo pLengendInfo;
  1753.             ILegendGroup pLengendGroup;
  1754.             pEnumLayer.Reset();
  1755.             for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
  1756.             {
  1757.                 if (pLayer is ILegendInfo)
  1758.                 {
  1759.                     pLengendInfo = pLayer as ILegendInfo;
  1760.                     for (int i = 0; i < pLengendInfo.LegendGroupCount; i++)
  1761.                     {
  1762.                         pLengendGroup = pLengendInfo.get_LegendGroup(i);
  1763.                         pLengendGroup.Visible = false;
  1764.                     }
  1765.                 }
  1766.             }
  1767.             this.axTOCControl.Update();
  1768.         }
  1769.         private void ctMenuMapExpandAll_Click(object sender, EventArgs e)
  1770.         {
  1771.             IEnumLayer pEnumLayer = this.mainMapControl.Map.get_Layers(null, false);
  1772.             if (pEnumLayer == null) return;
  1773.             ILayer pLayer;
  1774.             ILegendInfo pLengendInfo;
  1775.             ILegendGroup pLengendGroup;
  1776.             pEnumLayer.Reset();
  1777.             for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
  1778.             {
  1779.                 if (pLayer is ILegendInfo)
  1780.                 {
  1781.                     pLengendInfo = pLayer as ILegendInfo;
  1782.                     for (int i = 0; i < pLengendInfo.LegendGroupCount; i++)
  1783.                     {
  1784.                         pLengendGroup = pLengendInfo.get_LegendGroup(i);
  1785.                         pLengendGroup.Visible = true;
  1786.                     }
  1787.                 }
  1788.             }
  1789.             this.axTOCControl.Update();
  1790.         }
  1791.         private void ctMenuMapTurnOnAll_Click(object sender, EventArgs e)
  1792.         {
  1793.             IEnumLayer pEnumLayer = this.mainMapControl.Map.get_Layers(null, false);
  1794.             if (pEnumLayer == null) return;
  1795.             ILayer pLayer;
  1796.             pEnumLayer.Reset();
  1797.             for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
  1798.             {
  1799.                 pLayer.Visible = true;
  1800.             }
  1801.             this.mainMapControl.Refresh();
  1802.             this.axTOCControl.Update();
  1803.         }
  1804.         private void ctMenuMapTurnOffAll_Click(object sender, EventArgs e)
  1805.         {
  1806.             IEnumLayer pEnumLayer = this.mainMapControl.Map.get_Layers(null, false);
  1807.             if (pEnumLayer == null) return;
  1808.             ILayer pLayer;
  1809.             pEnumLayer.Reset();
  1810.             for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
  1811.             {
  1812.                 pLayer.Visible = false;
  1813.             }
  1814.             this.mainMapControl.Refresh();
  1815.             this.axTOCControl.Update();
  1816.         }
  1817.         private void btnDrawNewText_Click(object sender, EventArgs e)
  1818.         {
  1819.             this.drawBarCheckOnClick(((DevComponents.DotNetBar.ButtonItem)sender).Name);
  1820.             this.mainMapControl.CurrentTool = null;
  1821.         }
  1822.         private void drawBarCheckOnClick(string name)
  1823.         {
  1824.             foreach (DevComponents.DotNetBar.ButtonItem pButtonItem in this.barDraw.Items)
  1825.             {
  1826.                 pButtonItem.Checked = false;
  1827.             }
  1828.             ((DevComponents.DotNetBar.ButtonItem)this.barDraw.Items[name]).Checked = true;
  1829.         }
  1830.         private void txtNewText_KeyPress(object sender, KeyPressEventArgs e)
  1831.         {
  1832.             if (e.KeyChar == 'r' || e.KeyChar == 27)
  1833.             {
  1834.                 ITextElement pTextElement = new TextElementClass();
  1835.                 pTextElement.Text = this.txtNewText.Text;
  1836.                 IElement pElement = pTextElement as IElement;
  1837.                 pElement.Geometry = this.mapTextPoint;
  1838.                 IGraphicsContainer pGraphicsContainer = this.mainMapControl.Map as IGraphicsContainer;
  1839.                 pGraphicsContainer.AddElement(pElement, 0);
  1840.                 this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
  1841.                 this.txtNewText.Visible = false;
  1842.             }
  1843.         }
  1844.         private void txtNewText_Leave(object sender, EventArgs e)
  1845.         {
  1846.             ITextElement pTextElement = new TextElementClass();
  1847.             pTextElement.Text = this.txtNewText.Text;
  1848.             IElement pElement = pTextElement as IElement;
  1849.             pElement.Geometry = this.mapTextPoint;
  1850.             IGraphicsContainer pGraphicsContainer = this.mainMapControl.Map as IGraphicsContainer;
  1851.             pGraphicsContainer.AddElement(pElement, 0);
  1852.             this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
  1853.             this.txtNewText.Visible = false;
  1854.         }
  1855.         private void mainMapControl_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
  1856.         {
  1857.             this.EagleaxMapControl.Map = new MapClass();
  1858.             for (int i = 1; i <= this.mainMapControl.LayerCount; i++)
  1859.             {
  1860.                 this.EagleaxMapControl.AddLayer(this.mainMapControl.get_Layer(this.mainMapControl.LayerCount - i));
  1861.             }
  1862.             this.EagleaxMapControl.Extent = this.mainMapControl.FullExtent;
  1863.             this.EagleaxMapControl.Refresh();
  1864.         }
  1865.         private void btnCloseDoc_Click(object sender, EventArgs e)
  1866.         {
  1867.             if (this.mainMapControl.LayerCount > 0)
  1868.             {
  1869.                 DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  1870.                 if (result == DialogResult.Cancel) return;
  1871.                 if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null);
  1872.             }
  1873.             this.mainMapControl.Map = new MapClass();
  1874.             this.mainMapControl.DocumentFilename = "";
  1875.             this.m_controlsSynchronizer.ReplaceMap(this.mainMapControl.Map);
  1876.             this.Text = "LinGIS - LinInfo";
  1877.         }
  1878.         private void bubbleBtnSaveDoc_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1879.         {
  1880.             this.btnSaveDoc_Click(null, null);
  1881.         }
  1882.         private void bubbleBtnSaveDocAs_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1883.         {
  1884.             this.btnSaveDocAs_Click(null, null);
  1885.         }
  1886.         private void bubbleBtnCloseDoc_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
  1887.         {
  1888.             this.btnCloseDoc_Click(null, null);
  1889.         }
  1890.         private void btnAddLyr_Click(object sender, EventArgs e)
  1891.         {
  1892.             this.openFileDialog.Filter = "图层文件(*.lyr)|*.lyr";
  1893.             this.openFileDialog.Title = "请选择图层文件";
  1894.             if (this.openFileDialog.ShowDialog() == DialogResult.OK)
  1895.             {
  1896.                 Application.DoEvents();
  1897.                 try
  1898.                 {
  1899.                     this.mainMapControl.AddLayerFromFile(this.openFileDialog.FileName);
  1900.                     this.EagleaxMapControl.AddLayer(this.mainMapControl.get_Layer(0));
  1901.                     this.EagleaxMapControl.Extent = this.mainMapControl.FullExtent;
  1902.                 }
  1903.                 catch (Exception ex)
  1904.                 {
  1905.                     MessageBox.Show(ex.Message);
  1906.                 }
  1907.             } 
  1908.         }
  1909.         private void btnAddShp_Click(object sender, EventArgs e)
  1910.         {
  1911.             this.openFileDialog.Filter = "图层文件(*.shp)|*.shp";
  1912.             this.openFileDialog.Title = "请选择Shape文件";
  1913.             if (this.openFileDialog.ShowDialog() == DialogResult.OK)
  1914.             {
  1915.                 Application.DoEvents();
  1916.                 try
  1917.                 {
  1918.                     this.mainMapControl.AddShapeFile(System.IO.Path.GetDirectoryName(this.openFileDialog.FileName), System.IO.Path.GetFileName(this.openFileDialog.FileName));
  1919.                     this.EagleaxMapControl.AddLayer(this.mainMapControl.get_Layer(0));
  1920.                     this.EagleaxMapControl.Extent = this.mainMapControl.FullExtent;
  1921.                 }
  1922.                 catch (Exception ex)
  1923.                 {
  1924.                     MessageBox.Show(ex.Message);
  1925.                 }
  1926.             } 
  1927.         }
  1928.         private void btnAddCadAsFeat_Click(object sender, EventArgs e)
  1929.         {
  1930.             this.openFileDialog.Filter = "CAD文件(*.dwg)|*.dwg";
  1931.             this.openFileDialog.Title = "请选择CAD文件";
  1932.             if (this.openFileDialog.ShowDialog() == DialogResult.OK)
  1933.             {
  1934.                 Application.DoEvents();
  1935.                 try
  1936.                 {
  1937.                     IWorkspaceFactory pCADWorksapceFactory;
  1938.                     pCADWorksapceFactory = new CadWorkspaceFactoryClass();
  1939.                     IFeatureWorkspace pFeatureWorkspace;
  1940.                     pFeatureWorkspace = pCADWorksapceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(this.openFileDialog.FileName), 0) as IFeatureWorkspace;
  1941.                     IFeatureDataset pFeatureDataset;
  1942.                     pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(System.IO.Path.GetFileName(this.openFileDialog.FileName));
  1943.                     IFeatureClassContainer pFeatureClassContainer;
  1944.                     pFeatureClassContainer = pFeatureDataset as IFeatureClassContainer;
  1945.                     IFeatureClass pFeatureClass;
  1946.                     IFeatureLayer pFeatureLayer;
  1947.                     int i;
  1948.                     for (i = 0; i <= pFeatureClassContainer.ClassCount - 1; i++)
  1949.                     {
  1950.                         pFeatureClass = pFeatureClassContainer.get_Class(i);
  1951.                         if (pFeatureClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
  1952.                         {
  1953.                             pFeatureLayer = new CadAnnotationLayerClass();
  1954.                         }
  1955.                         else
  1956.                         {
  1957.                             pFeatureLayer = new FeatureLayerClass();
  1958.                         }
  1959.                         pFeatureLayer.Name = pFeatureClass.AliasName;
  1960.                         pFeatureLayer.FeatureClass = pFeatureClass;
  1961.                         this.mainMapControl.AddLayer(pFeatureLayer);
  1962.                         this.EagleaxMapControl.AddLayer(pFeatureLayer);
  1963.                     }
  1964.                     this.EagleaxMapControl.Extent = this.mainMapControl.FullExtent;
  1965.                 }
  1966.                 catch (Exception ex)
  1967.                 {
  1968.                     MessageBox.Show(ex.Message);
  1969.                 }
  1970.             }
  1971.         }
  1972.         private void btnAddCadAsDraw_Click(object sender, EventArgs e)
  1973.         {
  1974.             this.openFileDialog.Filter = "CAD文件(*.dwg)|*.dwg";
  1975.             this.openFileDialog.Title = "请选择CAD文件";
  1976.             if (this.openFileDialog.ShowDialog() == DialogResult.OK)
  1977.             {
  1978.                 Application.DoEvents();
  1979.                 try
  1980.                 {
  1981.                     IWorkspaceFactory pCADWorksapceFactory;
  1982.                     pCADWorksapceFactory = new CadWorkspaceFactoryClass();
  1983.                     ICadDrawingWorkspace pCadDrawingWorkspace;
  1984.                     pCadDrawingWorkspace = pCADWorksapceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(this.openFileDialog.FileName), 0) as ICadDrawingWorkspace;
  1985.                     ICadDrawingDataset pCadDrawingDataset;
  1986.                     pCadDrawingDataset = pCadDrawingWorkspace.OpenCadDrawingDataset(System.IO.Path.GetFileName(this.openFileDialog.FileName));
  1987.                     ICadLayer pCadLayer;
  1988.                     pCadLayer = new CadLayerClass();
  1989.                     pCadLayer.CadDrawingDataset = pCadDrawingDataset;
  1990.                     pCadLayer.Name = System.IO.Path.GetFileName(this.openFileDialog.FileName);
  1991.                     this.mainMapControl.AddLayer(pCadLayer);
  1992.                     this.EagleaxMapControl.AddLayer(pCadLayer);
  1993.                     this.EagleaxMapControl.Extent = this.mainMapControl.FullExtent;
  1994.                 }
  1995.                 catch (Exception ex)
  1996.                 {
  1997.                     MessageBox.Show(ex.Message);
  1998.                 }
  1999.             } 
  2000.         }
  2001.         private void btnDisplayFeeback_Click(object sender, EventArgs e)
  2002.         {
  2003.             LinGIS.DisplayFeedbackFrm newDisplayFeedbackFrm = new LinGIS.DisplayFeedbackFrm();
  2004.             newDisplayFeedbackFrm.Show();
  2005.         }
  2006.         private void btnAbout_Click(object sender, EventArgs e)
  2007.         {
  2008.             AboutFrm newAboutFrm = new AboutFrm();
  2009.             newAboutFrm.ShowDialog();
  2010.         }
  2011.         private void MainFrm_FormClosing(object sender, FormClosingEventArgs e)
  2012.         {
  2013.             if (this.mainMapControl.LayerCount > 0)
  2014.             {
  2015.                 DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  2016.                 if (result == DialogResult.Cancel)
  2017.                 {
  2018.                     e.Cancel = true;
  2019.                     return;
  2020.                 }
  2021.                 if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null);
  2022.             }
  2023.         }
  2024.     }
  2025. }