using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
namespace 选择元素
{
public
partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//定义颜色方法
private IRgbColor GetRGB(int r, int g, int b)
{
IRgbColor pRgbColor = new RgbColorClass(); //利用
IRgbColor 接口,分别设置R、G、B三个值参数
pRgbColor.Red = r;
pRgbColor.Green = g;
pRgbColor.Blue = b;
return pRgbColor; //
返回对象值
}
private void axMapControl1_OnMouseDown(object sender,
ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
IMap pMap;
IActiveView pActiveView;
pMap = axMapControl1.Map;
pActiveView = pMap as IActiveView;
ISegmentCollection pSegColl;
ILine pLine;
IRing pRing;
pSegColl = new RingClass();
pLine = new LineClass();
IPoint pPt1 = new PointClass();
pPt1.PutCoords(100, 100);
IPoint pPt2 = new PointClass();
pPt2.PutCoords(200, 100);
IPoint pPt3 = new PointClass();
pPt3.PutCoords(200, 300);
IPoint pPt4 = new PointClass();
pPt4.PutCoords(100, 600);
pLine.PutCoords(pPt1,
pPt2);
//点pPt1、pPt2……pPt4等的位置不一样,出来的图形效果是不一样的
object Missing1 = Type.Missing;
object Missing2 = Type.Missing;
pSegColl.AddSegment(pLine as ISegment, ref Missing1, ref
Missing2);
pLine = new LineClass();
pLine.PutCoords(pPt2, pPt3);
pSegColl.AddSegment(pLine as ISegment, ref Missing1, ref
Missing2);
pLine = new LineClass();
pLine.PutCoords(pPt3, pPt4);
pSegColl.AddSegment(pLine as ISegment, ref Missing1, ref
Missing2);
pRing = pSegColl as IRing;
pRing.Close();
IGeometryCollection pPolygon = new PolygonClass();
pPolygon.AddGeometry(pRing, ref Missing1, ref Missing2);
ISimpleFillSymbol pSimpleFillSym = new
SimpleFillSymbolClass();
//填充样式以及颜色
pSimpleFillSym.Style = esriSimpleFillStyle.esriSFSSolid;
pSimpleFillSym.Color = GetRGB(250, 50, 100);
IFillShapeElement pPolygonEle = new PolygonElementClass();
pPolygonEle.Symbol = pSimpleFillSym;
IElement pEle = pPolygonEle as IElement;
pEle.Geometry = (IGeometry)pPolygon;
IGraphicsContainer pGraphicsContainer;
pGraphicsContainer = pMap as IGraphicsContainer;
pGraphicsContainer.AddElement(pEle, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,
null, null);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,
null, null);
}
}
}