상속: System.Windows.Forms.Form
예제 #1
0
        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 = "";
                }
            }
        }
		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 = "";
				}
			}
		}