Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to do the following. Create a point on a map at a given coordinate (x,y) and then display text at that point. Right now I can create a shape file but nothing is displayed on the map. Hopefully someone can tell me why

Here is my code:

ArcDisplay.IRgbColor color = new RgbColorClass()
    Red   = 255,
    Green = 255,
    Blue  = 255

IPoint point = new PointClass()
    X = 0.0,
    Y = 0.0,
    Z = 0.0,
    SpatialReference = myMap.Map.SpatialReference

IElement elem = null;
ITextElement txtElement = new TextElementClass();
element = textElement as IElement;

ITextSymbol textSymbol = new TextSymbolClass();
textSymbol.Color = color;
textSymbol.Size = 16;
textSymbol.Font = (stdole.IFontDisp)OLE.GetIFontDispFromFont(new Font("Arial" , 16 , FontStyle.Bold);

element.Geometry = point as IGeometry;

textSymbol.Text = "My Test Text";
txtElement.Symbol = textSymbol;

((ITextElement)element).Symbol = textSymbol;

IGrpahicsLayer graphicsLayer = new CompositeGraphicsLayerClass();
((ILayer)graphicsLayer).Name = "Text Layer";
IGraphicsContainer graphicsContainer = graphicsLayer as IGraphicsContainer;
graphicsContainer.AddElement(element , 0);

myMap.AddLayer(graphicsLayer as ILayer);
((ILayer)graphicsLayer).Draw(esriDrawPhase.esriDPGeography , null , null);

Any ideas?

share|improve this question
up vote 2 down vote accepted

I think I used to do it like this while in non-dynamic-display mode (warning haven't used this code in a while): -- In dynamic display mode it will flicker - so you will need another method for that.

IActiveView activeView = mapControl.Map as IActiveView;
ITextElement pTextElement;
IElement pElement;
ICallout pCallout;
IFormattedTextSymbol pTextSymbol;
IGraphicsContainer pGraphicsContainer;

pTextElement = new TextElementClass();
pElement = pTextElement as IElement;
pTextElement.Text = message;

ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;

int x, y;
displayTransformation.FromMapPoint(anchorPoint, out x, out y);IPoint messagePoint = mapControl.ToMapPoint(x, y - 100); //this is in pixels 
pElement.Geometry = messagePoint;

pTextSymbol = new TextSymbol();
pCallout = new BalloonCallout();
pTextSymbol.Background = pCallout as ITextBackground;
pCallout.AnchorPoint = anchorPoint;
pTextElement.Symbol = pTextSymbol;

if (pGraphicsContainer == null) pGraphicsContainer = activeView as IGraphicsContainer; 
pGraphicsContainer.AddElement(pElement, 0);
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null);
share|improve this answer
pTextElement.Text = message; – PSU_Kardi Mar 3 '11 at 13:38

Just throwing this out there - it could be something that you've already checked, but sometimes we overlook the simple stuff (I'm guilty of this constantly). But are the labels turned on for the feature?

share|improve this answer
Labels are not turned off. Thanks though – PSU_Kardi Mar 3 '11 at 13:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.