Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.
    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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.