// 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. 页面按钮埋点+跟踪location.search

    <a href="javascript: void(0)" onclick="setUrl('https://baoxian.pingan.com/pa18shop ...

  2. linux 目录结构+常用命令+压缩命令+vim使用+及基础知识

    linux目录架构 / 根目录 /bin 常用的命令 binary file 的目录 /boot 存放系统启动时必须读取的档案,包括核心 (kernel) 在内 /boot/grub/menu.lst ...

  3. Python基础8:列表推导式(list)字典推导式(dict) 集合推导式(set)

    推导式分为列表推导式(list),字典推导式(dict),集合推导式(set)三种 1.列表推导式也叫列表解析式.功能:是提供一种方便的列表创建方法,所以,列表解析式返回的是一个列表格式:用中括号括起 ...

  4. 安卓Android Support Design Library——Snackbar

    介绍: Snackbar是Android Support Design Library库支持的一个控件,用于在界面下面提示一些关键信息,跟Toast不同的地方是SnackBar允许用户向右滑动消除它, ...

  5. Dubbo-Centos7管控台安装

    1.下载Tomcat7: $ wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.57/bin/apache-tomcat-7.0. ...

  6. Python -- 图片处理

    使用PIL库 转换图片格式(jpg  -->  png) from PIL import Image Image.open('E:/art.jpg').save('E:/art.png')

  7. 用as3.0制作一个滚动条组件

    本实例演示了实现一个滚动条基本功能的制作方法,没有添加改变皮肤,修改滚动条视框大小等功能,有兴趣的朋友可根据自己要求自行添加.使用时只需要通过以下一行代码创建滚动条组件: var myScrollba ...

  8. glog功能介绍

    1.   概述       Google glog是一个基于程序级记录日志信息的c++库,编程使用方式与c++的stream操作类似,例:        LOG(INFO) << &quo ...

  9. spark报错处理

    Spark报错处理 1.问题:org.apache.spark.SparkException: Exception thrown in awaitResult 分析:出现这个情况的原因是spark启动 ...

  10. Rails中的增删改查

      1.        rails中类与对象与SQL中表与行的关系 rails中提供了对象关系映射(ORM),将模型类映射至表,模型类的关联表名是类名小写后的复数形式,如类名Order,对应的表名为o ...