// Copyright 2010 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may 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 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 this command is clicked
/// </summary>
public override void OnClick()
{
IMapControl3 mapControl = null;

//get the MapControl from the hook in case 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 is an active edit session and whether edits have 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 to save the current document
DialogResult res = MessageBox.Show("Would you like to save the current document?", "AoView", MessageBoxButtons.YesNo, MessageBoxIcon.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# 新建文档CreateNewDocument的更多相关文章

  1. ubuntu 右键新建文档

    第一步.创建一个空白doc文档. 一定要是空白的,然后保存(另存为)到桌面,注意细节:1.保存到你能找到的地方,最好是桌面,以方便第二步拖动 2.注意下方的 “文件类型”,要选择doc格式. 3.注意 ...

  2. ID基本操作(新建文档,页面编码)5.8

    “文件”“新建”“文档”选择页数,页面大小.页面方向,“边距和分栏”设置上下左右的边距,栏数,如三栏 还可以改变分栏距离·改变排版方向,如图,垂直 单击“页面”可以查看我们的页面情况 超过两页会可以看 ...

  3. notepad++新建文档时,会出现语法错误的红色下波浪线

    notepad++新建文档时,会出现语法错误的红色下波浪线: 原因:新建文档时默认设置语言为PHP. 解决方法:修改默认语言为java或JavaScript,如下: 小结:打开文档时,也可能出现下波浪 ...

  4. deepin之添加右键新建文档选项

    deepin之添加右键新建文档选项 虽然Linux系统下所有皆文件,创建各种文件很简单,也很随意,但还是有人讨厌采用先创建空文件再改文件名的方式(比如我),我还是喜欢右键新建一个相应的源文件,可是默认 ...

  5. C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化

    转:http://www.cnblogs.com/lantionzy/archive/2009/10/23/1588511.html 1.新建Word文档 #region 新建Word文档/// &l ...

  6. Excel催化剂开源第5波-任务窗格在OFFICE2013中新建文档不能同步显示问题解决

    在OFFICE2013及之后,使用了单文档界面技术,不同于以往版本可以共享任务空格.功能区.所以当开发任务窗格时,需要考虑到每一个工作薄都关联一个任务窗格. 背景介绍 单文档界面摘录官方定义如下:对 ...

  7. Pycharm新建文档的模板设置

    下图演示的是关于python的文档的模板设置! 这样,以后的每一个新建的python的py文件,开头都会有下图中的两句:解释器路径与编码方式 步聚5的第二行内容打错了,应该是utf: #!/usr/b ...

  8. java操作mongodb数据库实现新建数据库,新建集合,新建文档

    *首先明确一点,要通过java代码创建mongodb数据库实例,需要同时创建集合和文档. 代码实现: /* 建立与mongodb数据库的连接,可指定参数,如:MongoClient client = ...

  9. 问题:C#打开一个文本文档往里面写数据,没有就新建文档 ;结果:c#FileStream文件读写(转)

    FileStream对象表示在磁盘或网络路径上指向文件的流.这个类提供了在文件中读写字节的方法,但经常使用StreamReader或 StreamWriter执行这些功能.这是因为FileStream ...

随机推荐

  1. php获取客户端ip地址方法

    /** * 获取客户端IP地址 * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字 * @param boolean $adv 是否进行高级模式获取(有 ...

  2. C#获取获取北京时间多种方法

    #region 获取网络时间 ///<summary> /// 获取中国国家授时中心网络服务器时间发布的当前时间 ///</summary> ///<returns> ...

  3. 用AR.js实现webAR(新手入门)

    开发需要准备的东西: ** 域名 命名 这里是测试

  4. JDK1.10+scala环境的搭建之linux环境(centos6.9)

    ---恢复内容开始--- 第一步:安装jdk1.10版本 进入网页 http://oracle.com/technetwork/java/javase/downloads/index.html  下载 ...

  5. IDEA里运行程序时出现Error:scalac:error while loading JUnit4 , Scala signature JUnit4 has wrong version错误的解决办法(图文详解)

    不多说,直接上干货! 问题详情 当我们在运行程序时,出现Error:scalac:error while loading JUnit4 , Scala signature JUnit4 has wro ...

  6. JS - 解决鼠标单击、双击事件冲突问题(原生js实现)

    由于鼠标双击时每一次触发双击事件都会引起两次单击事件和一次单击事件,原生的js不提供专门的双击事件. 因为业务原因,双击和单机都绑定了不同的业务,在双击的时候又触发了单机,影响了页面的正常显示 出现问 ...

  7. Glide的用法

    最基本用法 glide采用的都是流接口方式 简单的从网络加载图片 Glide.with(context).load(internetUrl).into(targetImageView); 从文件加载 ...

  8. iphoneX 适配

    1.iphoneX的尺寸  375*812   上边有44px的危险区,下边有34px的危险区,剩下的是安全区. 2.viewport设值cover <meta name="viewp ...

  9. PMP备考指南之第二章:项目运作环境

    本文已同步至 GitHub/Gitee/公众号,感兴趣的同学帮忙点波关注~ 第二章:项目运作环境 1. 事业环境因素.组织过程资产 事业环境因素 Enterprise Environmental Fa ...

  10. seajs源码分析(一)---整体结构以及module.js

    1,seajs的主要内容在module.js内部,最开始包含这么几个东西 var cachedMods = seajs.cache = {} var anonymousMeta var fetchin ...