Form1.cs
上传用户:xianghe012
上传日期:2022-07-02
资源大小:77k
文件大小:5k
源码类别:

GIS编程

开发平台:

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.esriSystem;
  9. using ESRI.ArcGIS.SystemUI;
  10. using ESRI.ArcGIS.Geometry;
  11. using ESRI.ArcGIS.Display;
  12. using ESRI.ArcGIS.Geodatabase;
  13. using ESRI.ArcGIS.Carto;
  14. using ESRI.ArcGIS.Controls;
  15. namespace ArcMap
  16. {
  17.      
  18.     public partial class FrmMain : Form
  19.     {
  20.         public IMapControl2 pMapControl;
  21.         public IToolbarControl2 pToolBarControl;
  22.         public ITOCControl2 pTocControl;
  23.        
  24.         public bool toolSelected = false;        
  25.         public FrmMain()
  26.         {
  27.             InitializeComponent();
  28.         }
  29.         private void FrmMain_Load(object sender, EventArgs e)
  30.         {
  31.             pMapControl = (IMapControl2)axMapControl1.Object;
  32.             pTocControl = (ITOCControl2)axTOCControl1.Object;
  33.             pToolBarControl = (IToolbarControl2)axToolbarControl1.Object;
  34.           
  35.             pToolBarControl.SetBuddyControl(pMapControl);
  36.             pTocControl.SetBuddyControl(pMapControl);
  37.             CreateToolBarItem();
  38.         }
  39.         private void CreateToolBarItem()
  40.         {
  41.             pToolBarControl.AddItem("esriControls.ControlsOpenDocCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  42.             pToolBarControl.AddItem("esriControls.ControlsAddDataCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  43.             pToolBarControl.AddItem("esriControls.ControlsMapZoomInTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  44.             pToolBarControl.AddItem("esriControls.ControlsMapZoomOutTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  45.             pToolBarControl.AddItem("esriControls.ControlsMapZoomInFixedCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  46.             pToolBarControl.AddItem("esriControls.ControlsMapZoomOutFixedCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  47.             pToolBarControl.AddItem("esriControls.ControlsMapPanTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  48.             pToolBarControl.AddItem("esriControls.ControlsMapFullExtentCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  49.             pToolBarControl.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  50.             pToolBarControl.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  51.             pToolBarControl.AddItem("esriControls.ControlsSelectFeaturesTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  52.             pToolBarControl.AddItem("esriControls.ControlsClearSelectionCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  53.             pToolBarControl.AddItem("esriControls.ControlsSelectTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  54.             pToolBarControl.AddItem("esriControls.ControlsMapIdentifyTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  55.             pToolBarControl.AddItem("esriControls.ControlsMapFindCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  56.             pToolBarControl.AddItem("esriControls.ControlsMapMeasureTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  57.         }
  58.         private void FeatureViaProperty_Click(object sender, EventArgs e)
  59.         {
  60.             FrmQuery fQuery = new FrmQuery(pMapControl);            
  61.             fQuery.Show();            
  62.         }
  63.         private void PropertyViaFeature_Click(object sender, EventArgs e)
  64.         {
  65.             toolSelected = true;
  66.         }
  67.         private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
  68.         {
  69.             //if (e.button == 1 && toolSelected==true)
  70.             //{
  71.             //    X1 = e.mapX;
  72.             //    Y1 = e.mapY;
  73.             //}
  74.             //if (e.button == 1 && toolSelected == true)
  75.             //{
  76.             //    IEnvelope pEnvelop = pMapControl.TrackRectangle();
  77.             //    pMapControl.Map.ClearSelection();
  78.             //    frmProperty fProperty = new frmProperty(pMapControl, pEnvelop);
  79.             //    fProperty.Show();
  80.             //}
  81.         }
  82.         private void axMapControl1_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
  83.         {
  84.             //if (e.button == 1 && toolSelected == true)
  85.             //{
  86.             //    X2 = e.mapX;
  87.             //    Y2 = e.mapY;
  88.             //    pEnvelop = new EnvelopeClass();
  89.             //    pEnvelop.XMin = X1;
  90.             //    pEnvelop.XMax = X2;
  91.             //    pEnvelop.YMin = Y2;
  92.             //    pEnvelop.YMax = Y1;
  93.             //}
  94.         }
  95.         private void panToolStripMenuItem_Click(object sender, EventArgs e)
  96.         {
  97.             ICommand command = new ControlsMapPanToolClass();
  98.             command.OnCreate(pMapControl); 
  99.             if (command.Enabled == true) 
  100.             { 
  101.                 pMapControl.CurrentTool = (ITool)command; 
  102.                
  103.             }
  104.         }
  105.     }
  106. }