ArcGIS Engine指导书4.doc
文本预览下载声明
ArcEngine开发实例四
一、实例目标及其实现的主要功能
1、学习编程实现绘制基本图形的方法;
2、学习编程实现修改基本图形的方法;
二、具体的实现过程及代码
1、如指导书中的过程,新建一个C#工程项目,并为默认建立的窗体分别添加 “MapControl”“LicenseControl”控件。
2、为窗体添加工具集控件,依次为工具集添加文字按钮,其text属性分别为“新建多义线”,“新建多边形”,“新建Bezier曲线”,“拉伸多义线”,“移动多义线节点”,“移动多边形节点”,其name属性分别为“btnNewPolyline”,“btnNewPolygon”,“btnNewBezierCurve”,“btnStretchLine”,“btnLineMovePoint”,“btnPolygonMovePoint”。同时设各个工具按钮的displaystyle属性为“Text”。
3、依次设置窗体上“MapControl”,“toolstrip1”的dock属性为fill和top。
4、添加ArcGIS的引用ESRI.ArcGIS.Geodatabase和ESRI.ArcGIS.ADF类库,在第一个窗体的代码窗口导入命名空间:
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Output;
5、在public partial class Form1 : Form代码下添加如下的初始化语句:
private IGraphicsContainer pGraphicContainer;
private IActiveView pActiveView;
private IDisplayFeedback pDisplayFeedback;
private IScreenDisplay pScreenDisplay;
private IElement hitElement;//鼠标点击的element
private IEnumElement pEnumElement;//element集合,移动几何对象中需要用到
private IPoint moveGeometryStartPoint;//移动几何对象时开始的位置
6、为窗体添加load事件,并添加以下代码:
private void Form1_Load(object sender, EventArgs e)
{
this.pGraphicContainer = this.axMapControl1.ActiveView.FocusMap as IGraphicsContainer;
this.pActiveView = this.axMapControl1.ActiveView;
this.pScreenDisplay = this.axMapControl1.ActiveView.ScreenDisplay; }
7、为 “axMapControl1”添加OnMouseDown事件,并添加如下代码:
try
{
if (e.button == 1)//按左键的话
{
IPoint pPoint = new PointClass();//在鼠标点击的位置生成一个点
pPoint.PutCoords(e.mapX, e.mapY);
if (this.btnNewPolyline.Checked)//画多义线
{
if (this.pDisplayFeedback == null)//如果是第一次点击,就建立第一个节点
{
this.pDisplayFeedback = new NewLineFeedbackClass();
显示全部