CreateNewDocument.cs
上传用户:hucuiqin88
上传日期:2022-06-19
资源大小:132k
文件大小:4k
源码类别:

按钮控件

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4. using System.Windows.Forms;
  5. using ESRI.ArcGIS.ADF.BaseClasses;
  6. using ESRI.ArcGIS.ADF.CATIDs;
  7. using ESRI.ArcGIS.Controls;
  8. using ESRI.ArcGIS.Carto;
  9. using ESRI.ArcGIS.SystemUI;
  10. namespace addPolylineTest
  11. {
  12.     /// <summary>
  13.     /// Summary description for CreateNewDocument.
  14.     /// </summary>
  15.     public class CreateNewDocument : BaseCommand
  16.     {
  17.         private IHookHelper m_hookHelper = null;
  18.         //constructor
  19.         public CreateNewDocument()
  20.         {
  21.             //update the base properties
  22.             base.m_category = ".NET Samples";
  23.             base.m_caption = "NewDocument";
  24.             base.m_message = "Create a new map";
  25.             base.m_toolTip = "Create a new map";
  26.             base.m_name = "DotNetTemplate_NewDocumentCommand";
  27.         }
  28.         #region Overriden Class Methods
  29.         /// <summary>
  30.         /// Occurs when this command is created
  31.         /// </summary>
  32.         /// <param name="hook">Instance of the application</param>
  33.         public override void OnCreate(object hook)
  34.         {
  35.             if (m_hookHelper == null)
  36.                 m_hookHelper = new HookHelperClass();
  37.             m_hookHelper.Hook = hook;
  38.         }
  39.         /// <summary>
  40.         /// Occurs when this command is clicked
  41.         /// </summary>
  42.         public override void OnClick()
  43.         {
  44.             IMapControl3 mapControl = null;
  45.             //get the MapControl from the hook in case the container is a ToolbarControl
  46.             if (m_hookHelper.Hook is IToolbarControl)
  47.             {
  48.                 mapControl = (IMapControl3)((IToolbarControl)m_hookHelper.Hook).Buddy;
  49.             }
  50.             //In case the container is MapControl
  51.             else if (m_hookHelper.Hook is IMapControl3)
  52.             {
  53.                 mapControl = (IMapControl3)m_hookHelper.Hook;
  54.             }
  55.             else
  56.             {
  57.                 MessageBox.Show("Active control must be MapControl!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  58.                 return;
  59.             }
  60.             //check to see if there is an active edit session and whether edits have been made
  61.             DialogResult result;
  62.             IEngineEditor engineEditor = new EngineEditorClass();
  63.             if ((engineEditor.EditState == esriEngineEditState.esriEngineStateEditing) && (engineEditor.HasEdits() == true))
  64.             {
  65.                 result = MessageBox.Show("Would you like to save your edits", "Save Edits", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  66.                 switch (result)
  67.                 {
  68.                     case DialogResult.Cancel:
  69.                         return;
  70.                     case DialogResult.No:
  71.                         engineEditor.StopEditing(false);
  72.                         break;
  73.                     case DialogResult.Yes:
  74.                         engineEditor.StopEditing(true);
  75.                         break;
  76.                 }
  77.             }
  78.             //allow the user to save the current document
  79.             DialogResult res = MessageBox.Show("Would you like to save the current document?", "AoView", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  80.             if (res == DialogResult.Yes)
  81.             {
  82.                 //launch the save command
  83.                 ICommand command = new ControlsSaveAsDocCommandClass();
  84.                 command.OnCreate(m_hookHelper.Hook);
  85.                 command.OnClick();
  86.             }
  87.             //create a new Map
  88.             IMap map = new MapClass();
  89.             map.Name = "Map";
  90.             //assign the new map to the MapControl
  91.             mapControl.DocumentFilename = string.Empty;
  92.             mapControl.Map = map;
  93.         }
  94.         #endregion
  95.     }
  96. }