Skip to content

Gradient text with TextRenderer.DrawText

James McCartney

Asked Jun 19, 2008, 10:51 AM EDT2 answers
Share
LinkedInX

Hello,

I was wondering if it was possible to draw text with a gradient fill using TextRenderer.DrawText.  I’m currently using Graphics.DrawString and a brush to get the effect I want.  I am getting a large performance increase using TextRenderer.DrawText, but I can’t figure out how to retain the ability to display text with a color gradient.

 

With DrawString:

 

gBrush = new LinearGradientBrush(rect,Color.LawnGreen, Color.DarkGreen,angle,true);

dc.DrawString(aString, boldFont, gBrush, 25,25);

 

With DrawText:

 

TextRenderer.DrawText(e.Graphics, aString, boldFont, aRect, Color.DarkGreen);

 

I imagine this has to be pretty simple because I have yet to find someone to ask this question before me yet, so everone else must be figuring it out, or I am going about this in a tottaly wrong direction.

 

Thanks!

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    I don't think you can do gradients using TextRenderer, only change the color and string format.  I suspect that is why its performance is faster than DrawString, since it doesn't require a brush to draw it.
    0
  • 0

    Thank You!

     

    That does make a lot of sense.  I will just have to figure out another way to do this entirely. 

     

    Thanks again for your help!

    0