int flags=0;
首先双击axMapControl1,然后添加以下代码:
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
IGeometry Geometry = null;
if (flags == 1)
{
Geometry = axMapControl1.TrackLine();//调用库函数画线
}
else if (flags == 2)
{
Geometry = axMapControl1.TrackRectangle();//调用库函数画矩形
}
else if (flags == 3)
{
Geometry = axMapControl1.TrackCircle();//调用库函数画圆
}
else if (flags == 4)
{
Geometry = axMapControl1.TrackPolygon();//调用库函数画面
}
else if (flags == 5)//画文本
{
IPoint point = new PointClass();
point.X = e.mapX;//注意这儿是地图的坐标而不是整个界面的坐标
point.Y = e.mapY;
Geometry = point as IGeometry;
}
if (flags >= 1 && flags <= 4)
{
drawMapShape(Geometry);//调用库函数的缺点在于不能设置宽度,颜色,显示
}
else if (flags == 5)
{
drawMapText(Geometry);//所以自定义函数将库函数画的对象显示出来
}
然后定义自定义函数drawMapShape(Geometry)和drawMapText(Geometry)以便于画图形对象
private void drawMapShape(IGeometry pGeom)
{
IRgbColor pColor;
pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Green = 0;
pColor.Blue = 255;
object symbol = null;
if (pGeom.GeometryType == esriGeometryType.esriGeometryPolyline)
{
ISimpleLineSymbol simpleLineSymbol;
simpleLineSymbol = new SimpleLineSymbolClass();
simpleLineSymbol.Color = pColor;
simpleLineSymbol.Width = 5;
symbol = simpleLineSymbol;
}
else
{
ISimpleFillSymbol simpleFillSymbol;
simpleFillSymbol=new SimpleFillSymbolClass();
simpleFillSymbol.Color=pColor;
symbol = simpleFillSymbol;
}
axMapControl1.DrawShape(pGeom, ref symbol);
}
private void drawMapText(IGeometry geometry)
{
IRgbColor Color = new RgbColorClass();
Color.Red = 0;
Color.Green = 0;
Color.Blue = 255;
ITextSymbol textSymbol = new TextSymbolClass();
textSymbol.Color = Color;
object symbol = textSymbol;
axMapControl1.DrawText(geometry, "制作人:潘红平",ref symbol);
}
最后在(线面矩形圆文本)的地方添加核心代码、
axMapControl1.CurrentTool = null;
线flags = 1;
矩形flags = 2;
圆flags = 3;
面flags = 4;
文本flags = 5;