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 ); }
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.' Is this a bug? I am using ArcGIS 10, service pack 2.
I don't have time right now to test this, but try the following:
Is this on a 64-bit machine?
If you provide some information regarding the values you are passing to your method, I will try to reproduce the issue.
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; }
Why should there be a difference between System.Drawing.Color.ToArgb() and the preceding code?