ClearType & Graphics.DrawString

I was making some fine tuning to my system prior to my TechEd Beat Box presentation … one of the tuning was to change the vs ide to use Consolas the cool ClearType font.

After applying the ClearType setting I've noticed something very strange…

The fonts of my Pattern – User Control seem to become very ugly…. (see the Bass Drum, Snare Drum & rim font) 

I’ve also seen that the buttons on the right seems fine… and they are actually also drawn the same way…i.e. using DrawString

I’ve started investigating it and it seems that if you are using Graphics.DrawString on transparent background you get the ugly font while if the background is not transparent it looks fine.

After some more deep investigation I found that one line can solve the problem:

Add a rendering hint just prior to the DrawString statement

g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;   <— This line solved it !
g.DrawString(text, font, Brushes.Black, new Point(x, 0));

Now everything is back to normal :-)


Comments have been disabled for this content.