在VS2010arcgis engine中mapcontrol中操作,实现点击触发一个点击事件,或者运行就直接加载,自动加载代码中添加的坐标值和线段属性画图。
private void button1_Click(object sender, EventArgs e)
{
//首先要实现容器接口
IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
pGraphicsContainer.DeleteAllElements();//清空容器里面所有的元素
//设置点的坐标
IPoint pPoint = new PointClass();
pPoint.PutCoords(310, 310);
//IMarkerElement用来获得symbol属性
IMarkerElement pMarkerElement = new MarkerElementClass();
//用ISimpleMarkerSymbol来设置点的属性
ISimpleMarkerSymbol pSymbol = new SimpleMarkerSymbolClass();
IRgbColor pRGBcolor = new RgbColorClass();
pRGBcolor.Red = 255;
pRGBcolor.Green = 0;
pRGBcolor.Blue = 0;
pSymbol.Color = pRGBcolor;//红色
pMarkerElement.Symbol = pSymbol;
//IElement用来获得Geometry属性
IElement pElement = pMarkerElement as IElement;
//把IPoint转换为为IGeoMetry也能实现
//IGeometry pGeometry = pPoint as IGeometry;
//pElement.Geometry = pGeometry;
pElement.Geometry = pPoint;
//在容器里添加元素
pGraphicsContainer.AddElement(pElement, 0);
pElement.Activate(axMapControl1.ActiveView.ScreenDisplay);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null);
}
//首先要实现容器接口
IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
pGraphicsContainer.DeleteAllElements();//清空容器里面所有的元素
//设置点的坐标
for (int i = 0; i <= 100; i = i + 10)
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(300 + i, 300 + i);
//IMarkerElement用来获得symbol属性
IMarkerElement pMarkerElement = new MarkerElementClass();
//用ISimpleMarkerSymbol来设置点的属性
ISimpleMarkerSymbol pSymbol = new SimpleMarkerSymbolClass();
IRgbColor pRGBcolor = new RgbColorClass();
pRGBcolor.Red = 255;
pRGBcolor.Green = 0;
pRGBcolor.Blue = 0;
pSymbol.Color = pRGBcolor;//红色
pMarkerElement.Symbol = pSymbol;
//IElement用来获得Geometry属性
IElement pElement = pMarkerElement as IElement;
//把IPoint转换为为IGeoMetry也能实现
//IGeometry pGeometry = pPoint as IGeometry;
//pElement.Geometry = pGeometry;
pElement.Geometry = pPoint;
//在容器里添加元素
pGraphicsContainer.AddElement(pElement, 0);
pElement.Activate(axMapControl1.ActiveView.ScreenDisplay);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null);