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
    public void DrawText( IActiveView view, string text, string fontName, int fontColor, float fontSize, IPoint point ) {

        ITextSymbol textSymbol = new TextSymbol();

        stdole.IFontDisp font = textSymbol.Font;
        font.Name = fontName;
        font.Size = (decimal)fontSize;
        textSymbol.Font = font;

        IColor color = textSymbol.Color;
        color.RGB = fontColor;
        textSymbol.Color = color;

        ITextElement textElement = new TextElementClass();
        textElement.Text = text;
        textElement.Symbol = textSymbol;
        textElement.ScaleText = true;

        IElement element = textElement as IElement;
        element.Geometry = point;

        view.GraphicsContainer.AddElement( element, 0 );

        view.PartialRefresh( esriViewDrawPhase.esriViewGraphics, element, null );

Can anyone suggest to me why this code always sets the font and size correctly but sometimes fails to set the color correctly? I always see the correct color in the 'textSymbol.Color' property after the line that sets it to 'color.' On the map (within a layer) it sometimes appears to 'combine' with that layer's fill color and off the map it sometimes appears 'blue.'

share|improve this question
up vote 0 down vote accepted

I was using System.Drawing.Color.ToArgb() to convert the System.Drawing.Color that a control was returning. I had already written:

public static int ConvertColorToRGB( System.Drawing.Color sourceColor ) {
    IRgbColor targetColor = new RgbColorClass();
    targetColor.Red = sourceColor.R;
    targetColor.Green = sourceColor.G;
    targetColor.Blue = sourceColor.B;
    targetColor.Transparency = sourceColor.A;
    return targetColor.RGB;

Which works.

share|improve this answer

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.