⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 C#编写的地理信息系统GIS入门程序
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

//ArcGIS Engine 引用
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.TOCControl;
using ESRI.ArcGIS.ToolbarControl;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Utility;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.CartoUI;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Framework;

namespace guo2
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private ESRI.ArcGIS.MapControl.AxMapControl axMapControl1;
		private ESRI.ArcGIS.TOCControl.AxTOCControl axTOCControl1;
		private ESRI.ArcGIS.ToolbarControl.AxToolbarControl axToolbarControl1;
		private IAoInitialize m_AoInitialize = new AoInitializeClass();
		private IToolbarMenu m_ToolbarMenu = new ToolbarMenuClass();      //弹出式菜单
		private System.Windows.Forms.Button cmdMapDoc;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;  
		private ITOCControl m_TOCControl;
		private System.Windows.Forms.SaveFileDialog saveFileDialog1;
		private System.Windows.Forms.Button cmdSave;
		private System.Windows.Forms.Button cmdSaveAs;
		private IMapDocument m_MapDocument;
		private System.Windows.Forms.TextBox txtMapDocument;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.CheckBox chkCustomization;
		private ICustomizeDialog m_CustomizeDialog = new CustomizeDialogClass();         //Customize被ToolbarControl使用
		private ICustomizeDialogEvents_OnStartDialogEventHandler startDialogE;           //Customize开启事件
		private ICustomizeDialogEvents_OnCloseDialogEventHandler closeDialogE;           //Customize关闭事件
		private System.Windows.Forms.StatusBar statusBar1;   
		private string sMapUnits;
		private System.Windows.Forms.Button clearall;
		private System.Windows.Forms.DateTimePicker dateTimePicker1;
		private System.Windows.Forms.Button selectfeature;
		private IApplication application;

		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.axMapControl1 = new ESRI.ArcGIS.MapControl.AxMapControl();
			this.axTOCControl1 = new ESRI.ArcGIS.TOCControl.AxTOCControl();
			this.axToolbarControl1 = new ESRI.ArcGIS.ToolbarControl.AxToolbarControl();
			this.cmdMapDoc = new System.Windows.Forms.Button();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.cmdSave = new System.Windows.Forms.Button();
			this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
			this.cmdSaveAs = new System.Windows.Forms.Button();
			this.txtMapDocument = new System.Windows.Forms.TextBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.chkCustomization = new System.Windows.Forms.CheckBox();
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.clearall = new System.Windows.Forms.Button();
			this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
			this.selectfeature = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.axTOCControl1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).BeginInit();
			this.SuspendLayout();
			// 
			// axMapControl1
			// 
			this.axMapControl1.Location = new System.Drawing.Point(200, 40);
			this.axMapControl1.Name = "axMapControl1";
			this.axMapControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapControl1.OcxState")));
			this.axMapControl1.Size = new System.Drawing.Size(464, 408);
			this.axMapControl1.TabIndex = 0;
			this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEventHandler(this.axMapControl1_OnMouseDown);
			this.axMapControl1.OnMouseMove += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseMoveEventHandler(this.axMapControl1_OnMouseMove);
			this.axMapControl1.OnMapReplaced += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMapReplacedEventHandler(this.axMapControl1_OnMapReplaced);
			// 
			// axTOCControl1
			// 
			this.axTOCControl1.Location = new System.Drawing.Point(0, 40);
			this.axTOCControl1.Name = "axTOCControl1";
			this.axTOCControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axTOCControl1.OcxState")));
			this.axTOCControl1.Size = new System.Drawing.Size(200, 408);
			this.axTOCControl1.TabIndex = 1;
			this.axTOCControl1.OnEndLabelEdit += new ESRI.ArcGIS.TOCControl.ITOCControlEvents_OnEndLabelEditEventHandler(this.axTOCControl1_OnEndLabelEdit);
			// 
			// axToolbarControl1
			// 
			this.axToolbarControl1.Location = new System.Drawing.Point(8, 8);
			this.axToolbarControl1.Name = "axToolbarControl1";
			this.axToolbarControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axToolbarControl1.OcxState")));
			this.axToolbarControl1.Size = new System.Drawing.Size(400, 26);
			this.axToolbarControl1.TabIndex = 2;
			this.axToolbarControl1.OnMouseMove += new ESRI.ArcGIS.ToolbarControl.IToolbarControlEvents_OnMouseMoveEventHandler(this.axToolbarControl1_OnMouseMove);
			// 
			// cmdMapDoc
			// 
			this.cmdMapDoc.Font = new System.Drawing.Font("GungsuhChe", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cmdMapDoc.Location = new System.Drawing.Point(0, 456);
			this.cmdMapDoc.Name = "cmdMapDoc";
			this.cmdMapDoc.Size = new System.Drawing.Size(64, 24);
			this.cmdMapDoc.TabIndex = 3;
			this.cmdMapDoc.Text = "LoadFile";
			this.cmdMapDoc.Click += new System.EventHandler(this.cmdMapDoc_Click);
			// 
			// cmdSave
			// 
			this.cmdSave.Font = new System.Drawing.Font("GungsuhChe", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cmdSave.Location = new System.Drawing.Point(66, 456);
			this.cmdSave.Name = "cmdSave";
			this.cmdSave.Size = new System.Drawing.Size(64, 24);
			this.cmdSave.TabIndex = 4;
			this.cmdSave.Text = "Save";
			this.cmdSave.Click += new System.EventHandler(this.saveButton_Click);
			// 
			// cmdSaveAs
			// 
			this.cmdSaveAs.Font = new System.Drawing.Font("GungsuhChe", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cmdSaveAs.Location = new System.Drawing.Point(132, 456);
			this.cmdSaveAs.Name = "cmdSaveAs";
			this.cmdSaveAs.Size = new System.Drawing.Size(64, 24);
			this.cmdSaveAs.TabIndex = 5;
			this.cmdSaveAs.Text = "SaveAs";
			this.cmdSaveAs.Click += new System.EventHandler(this.cmdSaveAs_Click);
			// 
			// txtMapDocument
			// 
			this.txtMapDocument.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtMapDocument.Location = new System.Drawing.Point(384, 464);
			this.txtMapDocument.Name = "txtMapDocument";
			this.txtMapDocument.ReadOnly = true;
			this.txtMapDocument.Size = new System.Drawing.Size(344, 21);
			this.txtMapDocument.TabIndex = 6;
			this.txtMapDocument.Text = "";
			// 
			// textBox1
			// 
			this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.textBox1.Font = new System.Drawing.Font("GungsuhChe", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.textBox1.Location = new System.Drawing.Point(296, 464);
			this.textBox1.Name = "textBox1";
			this.textBox1.ReadOnly = true;
			this.textBox1.Size = new System.Drawing.Size(80, 14);
			this.textBox1.TabIndex = 7;
			this.textBox1.Text = "打开文件路径:";
			// 
			// chkCustomization
			// 
			this.chkCustomization.Font = new System.Drawing.Font("GungsuhChe", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.chkCustomization.Location = new System.Drawing.Point(568, 8);
			this.chkCustomization.Name = "chkCustomization";
			this.chkCustomization.Size = new System.Drawing.Size(80, 24);
			this.chkCustomization.TabIndex = 8;
			this.chkCustomization.Text = "Customize";
			this.chkCustomization.CheckedChanged += new System.EventHandler(this.chkCustomization_CheckedChanged);
			// 
			// statusBar1
			// 
			this.statusBar1.Location = new System.Drawing.Point(0, 488);
			this.statusBar1.Name = "statusBar1";
			this.statusBar1.Size = new System.Drawing.Size(744, 22);
			this.statusBar1.TabIndex = 9;
			this.statusBar1.Text = "statusBar1";
			// 
			// clearall
			// 
			this.clearall.Font = new System.Drawing.Font("GungsuhChe", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.clearall.Location = new System.Drawing.Point(198, 456);
			this.clearall.Name = "clearall";
			this.clearall.Size = new System.Drawing.Size(64, 24);
			this.clearall.TabIndex = 10;
			this.clearall.Text = "ClearAll";
			this.clearall.Click += new System.EventHandler(this.clearall_Click);
			// 
			// dateTimePicker1
			// 
			this.dateTimePicker1.Location = new System.Drawing.Point(424, 8);
			this.dateTimePicker1.Name = "dateTimePicker1";
			this.dateTimePicker1.Size = new System.Drawing.Size(112, 21);
			this.dateTimePicker1.TabIndex = 11;
			// 
			// selectfeature
			// 
			this.selectfeature.Location = new System.Drawing.Point(664, 8);
			this.selectfeature.Name = "selectfeature";
			this.selectfeature.TabIndex = 12;
			this.selectfeature.Text = "select";
			this.selectfeature.Click += new System.EventHandler(this.selectfeature_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(744, 510);
			this.Controls.Add(this.selectfeature);
			this.Controls.Add(this.dateTimePicker1);
			this.Controls.Add(this.clearall);
			this.Controls.Add(this.statusBar1);
			this.Controls.Add(this.chkCustomization);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.txtMapDocument);
			this.Controls.Add(this.cmdSaveAs);
			this.Controls.Add(this.cmdSave);
			this.Controls.Add(this.cmdMapDoc);
			this.Controls.Add(this.axToolbarControl1);
			this.Controls.Add(this.axTOCControl1);
			this.Controls.Add(this.axMapControl1);
			this.Name = "Form1";
			this.Text = "程序演示";
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.axTOCControl1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}		

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//Create a new AoInitialize object
			if (m_AoInitialize == null)
			{
				System.Windows.Forms.MessageBox.Show("Unable to initialize. This application cannot run!");
				this.Close();
			}
			//Determine if the product is available
			esriLicenseStatus licenseStatus = (esriLicenseStatus) m_AoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine);
			if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)
			{
				licenseStatus = (esriLicenseStatus) m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
				if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
				{
					System.Windows.Forms.MessageBox.Show("The initialization failed. This application cannot run!");
					this.Close();
				}
			}
			else
			{
				System.Windows.Forms.MessageBox.Show("The ArcGIS Engine product is unavailable. This application cannot run!");
				this.Close();
			}
			sMapUnits = "Unknown";
			StatusBarPanel panel1 = new StatusBarPanel();
			StatusBarPanel panel2 = new StatusBarPanel();
			StatusBarPanel panel3 = new StatusBarPanel();
			statusBar1.Panels.Add(panel1);
			statusBar1.Panels.Add(panel2);
			statusBar1.Panels.Add(panel3);
			statusBar1.Panels[0].Style = StatusBarPanelStyle.Text;
			statusBar1.Panels[1].Style = StatusBarPanelStyle.Text;
			statusBar1.Panels[2].Style = StatusBarPanelStyle.Text;
			statusBar1.Panels[0].BorderStyle = StatusBarPanelBorderStyle.Sunken;
			statusBar1.Panels[1].BorderStyle = StatusBarPanelBorderStyle.Sunken;
			statusBar1.Panels[2].BorderStyle = StatusBarPanelBorderStyle.Sunken;
			statusBar1.Panels[0].AutoSize = StatusBarPanelAutoSize.Contents;
			statusBar1.Panels[1].AutoSize = StatusBarPanelAutoSize.Contents;
			statusBar1.Panels[2].AutoSize = StatusBarPanelAutoSize.Contents;
			//statusBar1.Panels[0].Width = (statusBar1.Width) / 5*2;
			//statusBar1.Panels[1].Width = (statusBar1.Width) / 5*2;
			//statusBar1.Panels[2].Width = (statusBar1.Width) / 5*1;
			statusBar1.Panels[0].ToolTipText = "显示工具的作用";
			statusBar1.Panels[0].Text = "";
			statusBar1.Panels[1].ToolTipText = "显示地图坐标及单位";
			statusBar1.Panels[1].Text = "";
			statusBar1.Panels[2].ToolTipText = "显示日期和时间";
			statusBar1.Panels[2].Text = System.DateTime.Today.ToShortDateString()+"  "+System.DateTime.Now.ToShortTimeString();
			statusBar1.ShowPanels = true ;

			m_TOCControl = (ITOCControl) axTOCControl1.Object;		
			

			//当缩放时禁止重绘
			//this.SetStyle(ControlStyles.EnableNotifyMessage,true);

			CreateCustomizeDialog();   //调用定制对话框函数

			//设置标签编辑为手动方式
			axTOCControl1.LabelEdit = esriTOCControlEdit.esriTOCControlManual;

			//Set the Buddy			
			axTOCControl1.SetBuddyControl(axMapControl1);
			axToolbarControl1.SetBuddyControl(axMapControl1);
			axToolbarControl1.ToolTips = true;
			axMapControl1.ShowMapTips = true;
			axMapControl1.TipDelay = 0;
			
			//设置BUTTON为灰色

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -