1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.IO;
  8. using System.Runtime.InteropServices;
  9. using ESRI.ArcGIS.esriSystem;
  10. using ESRI.ArcGIS.Carto;
  11. using ESRI.ArcGIS.Controls;
  12. using ESRI.ArcGIS.ADF;
  13. using ESRI.ArcGIS.SystemUI;
  14. namespace Demo2
  15. {
  16. public sealed partial class MainForm : Form
  17. {
  18. #region private members
  19. private IMapControl3 m_mapControl = null;
  20. private string m_mapDocumentName = string.Empty;
  21. private IToolbarMenu m_toolbarMenu;
  22. #endregion
  23. #region class constructor
  24. public MainForm()
  25. {
  26. InitializeComponent();
  27. }
  28. #endregion
  29. private void MainForm_Load(object sender, EventArgs e)
  30. {
  31. m_mapControl = (IMapControl3) axMapControl1.Object;
  32. //Load the Data into the MapControl1
  33. string sFilePath = @"C:ConferenceDataDemo Editing.mxd";
  34. if (m_mapControl.CheckMxFile(sFilePath))
  35. {
  36. m_mapControl.LoadMxFile(sFilePath, null, null);
  37. }
  38. else
  39. MessageBox.Show(sFilePath + " is not a valid ArcMap document");
  40. #region setup toolbar visibility
  41. menuSaveDoc.Enabled = false;
  42. editingToolStripMenuItem.Checked = true;
  43. inkToolStripMenuItem.Checked = false;
  44. GenericToolStripMenuItem.Checked = false;
  45. navigationToolStripMenuItem.Checked = true;
  46. axEditorToolbar.Visible = true;
  47. axNavigationToolbar.Visible = true;
  48. axExtraEditorToolbar.Visible = false;
  49. axInkToolbar.Visible = false;
  50. #endregion
  51. //EditorToolbar
  52. axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  53. axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  54. axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  55. axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
  56. axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
  57. axEditorToolbar.AddItem("esriControls.ControlsEditingAttributeCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  58. axEditorToolbar.AddItem("esriControls.ControlsEditingSketchPropertiesCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  59. axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
  60. axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  61. //ExtraEditorToolbar
  62. axExtraEditorToolbar.AddItem(new EditPropertiesCmd(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleTextOnly);
  63. axExtraEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
  64. axExtraEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  65. axExtraEditorToolbar.AddItem("esriControls.ControlsEditingCutCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
  66. axExtraEditorToolbar.AddItem("esriControls.ControlsEditingPasteCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  67. axExtraEditorToolbar.AddItem("esriControls.ControlsEditingCopyCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  68. axExtraEditorToolbar.AddItem("esriControls.ControlsEditingClearCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
  69. //Create a popup menu
  70. m_toolbarMenu = new ToolbarMenuClass();
  71. m_toolbarMenu.AddItem("esriControls.ControlsEditingSketchContextMenu", 0, 0, false, esriCommandStyles.esriCommandStyleTextOnly);
  72. //Share the Command Pool
  73. m_toolbarMenu.CommandPool = axEditorToolbar.CommandPool;
  74. }
  75. #region Main Menu event handlers
  76. private void menuNewDoc_Click(object sender, EventArgs e)
  77. {
  78. //execute New Document command
  79. ICommand command = new CreateNewDocument();
  80. command.OnCreate(m_mapControl.Object);
  81. command.OnClick();
  82. }
  83. private void menuOpenDoc_Click(object sender, EventArgs e)
  84. {
  85. //execute Open Document command
  86. ICommand command = new ControlsOpenDocCommandClass();
  87. command.OnCreate(m_mapControl.Object);
  88. command.OnClick();
  89. }
  90. private void menuSaveDoc_Click(object sender, EventArgs e)
  91. {
  92. //execute Save Document command
  93. if (m_mapControl.CheckMxFile(m_mapDocumentName))
  94. {
  95. //create a new instance of a MapDocument
  96. IMapDocument mapDoc = new MapDocumentClass();
  97. mapDoc.Open(m_mapDocumentName, string.Empty);
  98. //Make sure that the MapDocument is not readonly
  99. if (mapDoc.get_IsReadOnly(m_mapDocumentName))
  100. {
  101. MessageBox.Show("Map document is read only!");
  102. mapDoc.Close();
  103. return;
  104. }
  105. //Replace its contents with the current map
  106. mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);
  107. //save the MapDocument in order to persist it
  108. mapDoc.Save(mapDoc.UsesRelativePaths, false);
  109. //close the MapDocument
  110. mapDoc.Close();
  111. }
  112. }
  113. private void menuSaveAs_Click(object sender, EventArgs e)
  114. {
  115. //execute SaveAs Document command
  116. ICommand command = new ControlsSaveAsDocCommandClass();
  117. command.OnCreate(m_mapControl.Object);
  118. command.OnClick();
  119. }
  120. private void menuExitApp_Click(object sender, EventArgs e)
  121. {
  122. //exit the application
  123. Application.Exit();
  124. }
  125. #endregion
  126. //listen to MapReplaced evant in order to update the statusbar and the Save menu
  127. private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
  128. {
  129. //get the current document name from the MapControl
  130. m_mapDocumentName = m_mapControl.DocumentFilename;
  131. //if there is no MapDocument, diable the Save menu and clear the statusbar
  132. if (m_mapDocumentName == string.Empty)
  133. {
  134. menuSaveDoc.Enabled = false;
  135. statusBarXY.Text = string.Empty;
  136. }
  137. else
  138. {
  139. //enable the Save manu and write the doc name to the statusbar
  140. menuSaveDoc.Enabled = true;
  141. statusBarXY.Text = Path.GetFileName(m_mapDocumentName);
  142. }
  143. }
  144. private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
  145. {
  146. statusBarXY.Text = string.Format("{0}, {1}  {2}", e.mapX.ToString("#######.##"), e.mapY.ToString("#######.##"), axMapControl1.MapUnits.ToString().Substring(4));
  147. }
  148. private void editingToolStripMenuItem_Click(object sender, EventArgs e)
  149. {
  150. if (axEditorToolbar.Visible == false)
  151. {
  152. axEditorToolbar.Visible = true;
  153. editingToolStripMenuItem.Checked = true;
  154. }
  155. else
  156. {
  157. axEditorToolbar.Visible = false;
  158. editingToolStripMenuItem.Checked = false;
  159. }
  160. }
  161. private void inkToolStripMenuItem_Click(object sender, EventArgs e)
  162. {
  163. if (axInkToolbar.Visible == false)
  164. axInkToolbar.Visible = true;
  165. else
  166. axInkToolbar.Visible = false;
  167. }
  168. private void navigationToolStripMenuItem_Click(object sender, EventArgs e)
  169. {
  170. if (axNavigationToolbar.Visible == false)
  171. axNavigationToolbar.Visible = true;
  172. else
  173. axNavigationToolbar.Visible = false;
  174. }
  175. private void bookmarksToolStripMenuItem_Click(object sender, EventArgs e)
  176. {
  177. if (axExtraEditorToolbar.Visible == false)
  178. axExtraEditorToolbar.Visible = true;
  179. else
  180. axExtraEditorToolbar.Visible = false;
  181. }
  182. private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
  183. {
  184. if (e.button == 2) m_toolbarMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);
  185. }
  186. }
  187. }

Arcengine编辑代码的更多相关文章

  1. VS2010在运行状态下编辑代码

    在VS2010环境下,当程序处于调试运行状态时,编辑代码会出现下图提示框: 这就给边编辑代码边查看程序运行效果带来不便. 解决方法:在程序没有运行的时候,打开菜单“工具”——>“选项”——> ...

  2. 如何让 Drupal 使用 Wordpress 形式的编辑代码?

    如果你曾有过将 Wordpress 网站迁移到 Drupal 的经验,很可能客户会问的第一件事就是如何为 Drupal 添加编辑代码. Wordpress 中的 Shortcodes 插件让使用者可以 ...

  3. VS编辑代码的时候,都会自动在资源浏览器里将文件所在项目展开

    如何设置VS编辑代码的时候,都会自动在资源浏览器里将文件所在项目展开 工具-选项-项目和解决方案-常规-在解决方案资源管理器中跟踪活动项(C)

  4. 在线编辑代码[django]版本

    再国内,做什么都这么吃力.连aliyun 的ssh 都被封这是什么世道,所以做一个在线编辑代码的忙忙碌碌有点粗糙.大家见谅​1. [代码]views.py #-*- coding:utf-8 -*-  ...

  5. 【01】在 Github 上编辑代码

    [01]在 Github 上编辑代码 当你使用 GitHub,看一些文件(任何的文本文件或者仓库),能看到一个顶部右侧有一个小铅笔图标.点击即可编辑文档. 完成后,按照提示点击「Propose fil ...

  6. 用vscode编辑代码

    本教程只适用于用vs code编辑代码,并不是用vs code调试,调试还是老实用keil吧,干货开始.... 废话不多说 第一步:去微软下载一个vs code,顺带百度了解一下vs code强大的功 ...

  7. 安装Pycharm(方便编辑代码的IDE(编辑器))以及 使用Pycharm新建项目

    安装Pycharm(方便编辑代码的IDE(编辑器))以及 使用Pycharm新建项目 一.下载安装Pycharm 首先要下载Pycharm这个软件,官网的下载地址是: http://www.jetbr ...

  8. Eclipse里编辑代码,进度条出现“Remote System Explorer Operation”解决方法

    Eclipse里编辑代码,进度条出现"Remote System Explorer Operation",导致Eclipse有卡顿. 解决方法: Eclipse -> Pre ...

  9. ArcEngine编辑保存错误:Unable to create logfile system tables

    通过ArcEngine对多个SDE中多个图层进行批量编辑处理,其中有部分图层在结束编辑的时候出现错误提示(部分图层可以,只有两个数据较多的图层保存失败). 错误信息:Unable to create ...

随机推荐

  1. 【xsy1144】选物品 主席树

    题目大意:$N$ 件物品摆成一排,给每个物品定义两个属性 $A$ 和$ B$,两件物品的 差异度 定义为它们两种属性的差的绝对值中较大的一个.如果要求出一些物品的差异度,我们先定义一个 理想物品,使它 ...

  2. redis允许内网访问

    如题有A.B两台服务器. A服务器上装有reis,内网IP:192.168.0.1 B服务器需要访问A服务器上的redis 一.修改A服务器上redis.conf文件 bind 192.168.0.1 ...

  3. (转)http://blog.csdn.net/renfufei/article/details/38474435

    原文:http://blog.csdn.net/renfufei/article/details/38474435

  4. 简述C和C++的学习历程

    总是被问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复. 一家之言,欢迎拍砖哈. 1.可以考虑先学习C. 大多数时候,我们学习语言的目的,不是为了成为一个语言专家,而是希望 ...

  5. Web服务端性能提升实践

    随着互联网的不断发展,日常生活中越来越多的需求通过网络来实现,从衣食住行到金融教育,从口袋到身份,人们无时无刻不依赖着网络,而且越来越多的人通过网络来完成自己的需求. 作为直接面对来自客户请求的Web ...

  6. eclipse maven插件创建maven项目

    1.下载好maven压缩包http://maven.apache.org/ ,解压后放到想要安装的目录,如E:/server/maven,然后配置好maven环境变量,找到maven安装目录下conf ...

  7. Cocos2d-x游戏导出android工程,提取cocos的so文件

      Cocos2d-x游戏导出android工程,提取cocos的so文件   原本cocos游戏的android工程编译时,需要将cocos的库文件进行编译,这些文件大部分是cpp文件, 使用ndk ...

  8. windows设置多用户模式

    在实际使用我们较多使用的都是windows系统的单用户模式,它意味着当我们登录一个用户的时候如果另外一个用户也在登录,那么就得等待另外一个用户退出后才可以登录我们这个用户,但是实际需求中,我们经常会遇 ...

  9. 判断产品Key的正则表达式(格式: ABCD1-ABCD2-ABCD3-ABCD4-ABCD5)

    正则表达式: ^[A-Za-z0-9]{5}-[A-Za-z0-9]{5}-[A-Za-z0-9]{5}-[A-Za-z0-9]{5}-[A-Za-z0-9]{5}$ 改进: ^([A-Za-z0-9 ...

  10. java将list转为树形结构的方法

    目录 1.通过转化成json封装数据 2.通过java8 stream转换 1.通过转化成json封装数据 原始数据如下 [ { "name":"甘肃省", & ...