Question

I feel like I've read a question similar to this but I can't find it, so please close if duplicate.

I am trying to draw text with Graphics::DrawString with a monospace font (Consolas). However, when I draw the text, the letters are not evenly spaced. Here's what it looks like:

enter image description here

As you can see, the letters are clustered into groups of two and three. I read this article and I thought I had taken adequate steps to avoid it by using StringFormat::GenericTypographic, but apparently not. I am also using TextRenderingHintClearTypeGridFit because all the others look like junk (and there's no TextRenderingHintClearType without the GridFit part).

How can I draw text like all the other programs that draw text with a monospace font so that it looks right?

Was it helpful?

Solution

The issue is that GDI+ uses a different (and long since abandoned) system for drawing text. Starting with .NET framework 2.0, Microsoft changed all the controls to actually use GDI for text rendering, rather than GDI+. Text rendering in GDI is hardware accelerated, and continued to get improvements with character rendering, Uniscribe, ligatures. Text rendering in GDI+ is not hardware accelerated, and not getting any fixes or improvements.

GDI can also draw anti-aliased, use CLEARTYPE_QUALITY or ANTIALIASED_QUALITY.

Here's a comparison of

  • GDI+ (Graphics.DrawString)
  • GDI (TextRenderer.DrawText)

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top