如何在MapControl界面添加双击事件实现标绘及符号样式更改

时间:2022-07-10 16:06:21

private void axMapControl1_OnDoubleClick(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnDoubleClickEvent e)
{
if (this._App.CurrentTool == "ESRITool") return;//实现对界面正在激活状态下工具的选取,不同tool实现不同双击事件
if (this._App.CurrentTool == "ESRIToolMe")
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);

ILayer player = this.GetGraphLayer("标绘图层");
IGraphicsContainer pGraphicsContainer = player as IGraphicsContainer;
IEnumElement pEnumElement = pGraphicsContainer.LocateElements(pPoint, 1);
if (pEnumElement != null)
{
IElement pElement = pEnumElement.Next();
if (pElement is ITextElement)
{

ITextElement ptextElement = pElement as ITextElement;

FrmSymbolShow1 pLabelEditCallout = new FrmSymbolShow1("TEXT");
pLabelEditCallout.ShowDialog();

ptextElement.Symbol = pLabelEditCallout.StyleGalleryItem.Item as ITextSymbol;

pGraphicsContainer.DeleteElement(pElement);
pGraphicsContainer.AddElement(pElement, 0);
//这两句可以用pGraphicsContainer.UpdataElement(pElement);来代替
}
else if (pElement is ILineElement)
{
ILineElement ptextElement = pElement as ILineElement;

FrmSymbolShow1 pLabelEditCallout = new FrmSymbolShow1("LINE");
pLabelEditCallout.ShowDialog();

ptextElement.Symbol = pLabelEditCallout.StyleGalleryItem.Item as ILineSymbol;

pGraphicsContainer.DeleteElement(pElement);
pGraphicsContainer.AddElement(pElement, 0);
}
else if (pElement is IFillShapeElement)
{
IFillShapeElement ptextElement = pElement as IFillShapeElement;

FrmSymbolShow1 pLabelEditCallout = new FrmSymbolShow1("SHAPE");
pLabelEditCallout.ShowDialog();

ptextElement.Symbol = pLabelEditCallout.StyleGalleryItem.Item as IFillSymbol;

pGraphicsContainer.DeleteElement(pElement);
pGraphicsContainer.AddElement(pElement, 0);
}

_App.axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
if (this._App.CurrentTool != null)
{
try
{
this._App.MapControl.CurrentTool.Deactivate();
}
catch { }
this._App.MapControl.CurrentTool = null;
this._tool = this._App.ToolCol[this._App.CurrentTool];
this._tool.OnDblClick(e.button, e.shift, e.x, e.y);
}
}