Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do my Windows Forms strings look so ugly when anti-aliased?

I'm rendering some strings manually on top of a GraphicsBox, because you can't have a Label with a treansparent backdrop.

No matter which rendering mode I try though, I can't get the strings to look any good (ie. as they would appear in Word or in a graphics program.

Here's a picture of the interface mockup compared to what renders onscreen: enter image description here

Unfortunately StackOverflow seems to shrink the picture so here's a direct link too: http://i.stack.imgur.com/vYFaF.png

And here's the code used to render:

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
  Graphics labelDrawing = e.Graphics;
  labelDrawing.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

  labelDrawing.DrawString("Setup Progress", new Font("Calibri", 10, FontStyle.Bold, GraphicsUnit.Point, 0), new SolidBrush(Color.Black), new Point(12, 9));
  labelDrawing.DrawString("The following components are being configured.", new Font("Calibri", 10, FontStyle.Regular, GraphicsUnit.Point, 0), new SolidBrush(Color.Black), new Point(24, 27));
}

I've tried changing the TextRenderingHint to every option in turn, but no matter what I try if there's any antialiasing then it comes out in a blurry, smeared mess like in the screenshot. Any idea?

like image 978
Coxy Avatar asked Nov 06 '22 19:11

Coxy


1 Answers

You can have transparent labels in .NET.
Check out this article on CodeProject on How to Use Transparent Images and Labels in Windows Forms

As for you drawing problem Calibri doesn't have a native font size of 10. You can verify this in Control Panel->Fonts. The smallest native font size is 12 (on my machine at least). Change you from size to 12 and you will see it's much better.

When you don't use native font sizes somewhere under the hood Windows/.NET/GDI+ will attempt to scale the font for you. This scaling is most likely causing your problem.

like image 102
ParmesanCodice Avatar answered Nov 15 '22 05:11

ParmesanCodice