public void CreateTextElment(double x, double y)
{
IPoint pPoint = new PointClass();
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = pMap as IActiveView;
IGraphicsContainer pGraphicsContainer;
IElement pElement = new MarkerElementClass();
IElement pTElement = new TextElementClass();
pGraphicsContainer = (IGraphicsContainer)pActiveView;
IFormattedTextSymbol pTextSymbol = new TextSymbolClass();
IBalloonCallout pBalloonCallout = CreateBalloonCallout(x, y);
IRgbColor pColor = new RgbColorClass();
pColor.Red = 150;
pColor.Green = 0;
pColor.Blue = 0;
pTextSymbol.Color = pColor;
ITextBackground pTextBackground;
pTextBackground = (ITextBackground)pBalloonCallout;
pTextSymbol.Background = pTextBackground;
((ITextElement)pTElement).Symbol = pTextSymbol;
((ITextElement)pTElement).Text = "测试";
pPoint.X = x + 42;
pPoint.Y = y + 42;
pTElement.Geometry = pPoint;
pGraphicsContainer.AddElement(pTElement, 1);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
public IBalloonCallout CreateBalloonCallout(double x, double y)
{
IRgbColor pRgbClr = new RgbColorClass();
pRgbClr.Red = 255;
pRgbClr.Blue = 255;
pRgbClr.Green = 255;
ISimpleFillSymbol pSmplFill = new SimpleFillSymbolClass();
pSmplFill.Color = pRgbClr;
pSmplFill.Style. = esriSimpleFillStyle.esriSFSSolid;
IBalloonCallout pBllnCallout = new BalloonCalloutClass();
pBllnCallout.Style. = esriBalloonCalloutStyle.esriBCSRectangle;
pBllnCallout.Symbol = pSmplFill;
pBllnCallout.LeaderTolerance = 1;
IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();
pPoint.X = x;
pPoint.Y = y;
pBllnCallout.AnchorPoint = pPoint;
return pBllnCallout;
}