Copyright ESRI
//
All rights reserved Under the copyright laws of the States
and applicable international laws, treaties, and conventions.
//
Freely redistribute and use this sample code, with or
Without modification, provided you include the original copyright
Notice and use restrictions.
//
See the use restrictions at <your ArcGIS install Location>/developerkit10.0/userestrictions.txt.
//
Using System;
Using System.Drawing;
Using System.Runtime.InteropServices;
Using System.Windows.Forms;
Using ESRI. ArcGIS.ADF.BaseClasses;
Using ESRI. ArcGIS.ADF.CATIDs;
Using ESRI. Arcgis.controls;
Using ESRI. Arcgis.carto;
Using ESRI. Arcgis.systemui;
Namespace TemporalStatistics2008
{
<summary>
Summary description for CreateNewDocument.
</summary>
public class Createnewdocument:basecommand
{
Private Ihookhelper m_hookhelper = null;
Constructor
Public CreateNewDocument ()
{
Update the base properties
Base.m_category = ". NET Samples";
Base.m_caption = "NewDocument";
Base.m_message = "Create a new map";
Base.m_tooltip = "Create a new map";
Base.m_name = "Dotnettemplate_newdocumentcommand";
}
#region Overriden Class Methods
<summary>
Occurs when the This command is created
</summary>
<param name= "Hook" >instance of the Application</param>
public override void OnCreate (object hook)
{
if (M_hookhelper = = null)
M_hookhelper = new Hookhelperclass ();
M_hookhelper.hook = Hook;
}
<summary>
Occurs when the this command is clicked
</summary>
public override void OnClick ()
{
IMapControl3 Mapcontrol = null;
Get the Mapcontrol from the hook with the container is a Toolbarcontrol
if (M_hookhelper.hook is Itoolbarcontrol)
{
Mapcontrol = (IMapControl3) ((Itoolbarcontrol) m_hookhelper.hook). Buddy;
}
In case the container is Mapcontrol
else if (M_hookhelper.hook is IMapControl3)
{
Mapcontrol = (IMapControl3) M_hookhelper.hook;
}
Else
{
MessageBox.Show ("Active control must be mapcontrol!", "Warning", MessageBoxButtons.OK, messageboxicon.exclamation);
Return
}
Check to see if there are an active edit session and whether edits has been made
DialogResult result;
Iengineeditor engineeditor = new Engineeditorclass ();
if (engineeditor.editstate = = esriengineeditstate.esrienginestateediting) && (engineeditor.hasedits () = = true))
{
result = MessageBox.Show ("Would you like to save your edits", "save Edits", Messageboxbuttons.yesnocancel, MessageBoxIcon. Question);
Switch (Result)
{
Case DialogResult.Cancel:
Return
Case dialogresult.no:
Engineeditor.stopediting (FALSE);
Break
Case Dialogresult.yes:
Engineeditor.stopediting (TRUE);
Break
}
}
Allow the user-save the current document
DialogResult res = MessageBox.Show ("Would to save the current document?", "Aoview", Messageboxbuttons.yesno, Mess Ageboxicon.question);
if (res = = Dialogresult.yes)
{
Launch the Save command
ICommand command = new Controlssaveasdoccommandclass ();
Command. OnCreate (M_hookhelper.hook);
Command. OnClick ();
}
Create a new Map
IMap map = new Mapclass ();
Map. Name = "Map";
Assign the new map to the Mapcontrol
Mapcontrol.documentfilename = string. Empty;
Mapcontrol.map = Map;
}
#endregion
}
}
C # New Document CreateNewDocument