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

📄 loadmap.cs

📁 利用CSharp进行二次开发
💻 CS
字号:
/*
 Copyright 1995-2005 ESRI

 All rights reserved under the copyright laws of the United States.

 You may freely redistribute and use this sample code, with or without modification.

 Disclaimer: THE SAMPLE CODE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 
 WARRANTIES, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESRI OR 
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 INTERRUPTION) SUSTAINED BY YOU OR A THIRD PARTY, HOWEVER CAUSED AND ON ANY 
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY 
 WAY OUT OF THE USE OF THIS SAMPLE CODE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 SUCH DAMAGE.

 For additional information contact: Environmental Systems Research Institute, Inc.

 Attn: Contracts Dept.

 380 New York Street

 Redlands, California, U.S.A. 92373 

 Email: contracts@esri.com
*/

using System;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;

namespace LoadMapControl
{
	public class frmMain : System.Windows.Forms.Form
	{
		public  System.Windows.Forms.TextBox txtPath;
		private System.Windows.Forms.Button cmdLoadDoc;
		public ESRI.ArcGIS.PageLayoutControl.AxPageLayoutControl axPageLayoutControl1;

		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private ESRI.ArcGIS.LicenseControl.AxLicenseControl axLicenseControl1;
		public System.ComponentModel.Container components = null;

		public frmMain()
		{
			InitializeComponent();
		}

		protected override void Dispose( bool disposing )
		{		
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
				ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown();

			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
			this.txtPath = new System.Windows.Forms.TextBox();
			this.cmdLoadDoc = new System.Windows.Forms.Button();
			this.axPageLayoutControl1 = new ESRI.ArcGIS.PageLayoutControl.AxPageLayoutControl();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.axLicenseControl1 = new ESRI.ArcGIS.LicenseControl.AxLicenseControl();
			((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit();
			this.SuspendLayout();
			// 
			// txtPath
			// 
			this.txtPath.Enabled = false;
			this.txtPath.Location = new System.Drawing.Point(8, 40);
			this.txtPath.Name = "txtPath";
			this.txtPath.Size = new System.Drawing.Size(352, 20);
			this.txtPath.TabIndex = 1;
			this.txtPath.Text = "";
			// 
			// cmdLoadDoc
			// 
			this.cmdLoadDoc.Location = new System.Drawing.Point(232, 8);
			this.cmdLoadDoc.Name = "cmdLoadDoc";
			this.cmdLoadDoc.Size = new System.Drawing.Size(128, 24);
			this.cmdLoadDoc.TabIndex = 2;
			this.cmdLoadDoc.Text = "Load Map Document";
			this.cmdLoadDoc.Click += new System.EventHandler(this.cmdLoadDoc_Click);
			// 
			// axPageLayoutControl1
			// 
			this.axPageLayoutControl1.Location = new System.Drawing.Point(8, 64);
			this.axPageLayoutControl1.Name = "axPageLayoutControl1";
			this.axPageLayoutControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axPageLayoutControl1.OcxState")));
			this.axPageLayoutControl1.Size = new System.Drawing.Size(352, 368);
			this.axPageLayoutControl1.TabIndex = 3;
			// 
			// axLicenseControl1
			// 
			this.axLicenseControl1.Enabled = true;
			this.axLicenseControl1.Location = new System.Drawing.Point(32, 88);
			this.axLicenseControl1.Name = "axLicenseControl1";
			this.axLicenseControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axLicenseControl1.OcxState")));
			this.axLicenseControl1.Size = new System.Drawing.Size(200, 50);
			this.axLicenseControl1.TabIndex = 4;
			// 
			// frmMain
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(376, 438);
			this.Controls.Add(this.axLicenseControl1);
			this.Controls.Add(this.axPageLayoutControl1);
			this.Controls.Add(this.cmdLoadDoc);
			this.Controls.Add(this.txtPath);
			this.Name = "frmMain";
			this.Text = "Load Map Document";
			((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run( new frmMain());
		}

		
		private void cmdLoadDoc_Click(object sender, System.EventArgs e)
		{
			//Open a file dialog for selecting map documents
			openFileDialog1.Title = "Browse Map Document";
			openFileDialog1.Filter = "Map Documents (*.mxd, *.mxt, *.pmf)|*.pmf; *.mxt; *.mxd";
			openFileDialog1.ShowDialog();

			//Exit if no map document is selected
			string sFilePath = openFileDialog1.FileName;
			if (sFilePath == "") return;

			bool bPass, bIsMapDoc;
			IMapDocument ipMapDoc;
			ipMapDoc = new MapDocumentClass();

			//Check if the map document is password protected
			bPass = ipMapDoc.get_IsPasswordProtected(sFilePath);

			if(bPass)
			{
				//Disable the main form
				this.Enabled = false;

				//Show the password dialog
				frmPassword Form2 = new frmPassword();
				Form2.ShowDialog (this);
				int check = Form2.Check; 
					
				//OK button pressed					
				if (check == 1)
				{
					try
					{
						//Set a waiting cursor
						Cursor.Current = Cursors.WaitCursor;
								
						//Load the password protected map
						axPageLayoutControl1.LoadMxFile(sFilePath, Form2.Password); 
						txtPath.Text = sFilePath;
						this.Enabled = true;

						//Set a default cursor
						Cursor.Current = Cursors.Default; 
					}
					catch
					{
						this.Enabled = true;
						MessageBox.Show("The Password was incorrect!");
					}
				}
				else
				{
					this.Enabled = true;
				}
			}
			else  
			{
				//Check whether the file is a map document
				bIsMapDoc = axPageLayoutControl1.CheckMxFile(sFilePath);
				
				if(bIsMapDoc)
				{
					Cursor.Current = Cursors.WaitCursor;
					
					//Load the Mx document	
					axPageLayoutControl1.LoadMxFile(sFilePath, Type.Missing); 
					txtPath.Text = sFilePath;
					//Set a default cursor
					Cursor.Current = Cursors.Default; 
				}
				else
				{
					MessageBox.Show(sFilePath + " is not a valid ArcMap document");
					sFilePath = "";
				}
			}
		}

	}
}

⌨️ 快捷键说明

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