6

Does anyone know how to make labels, or text, smoother? At the moment they look quite jagged. As I want to make the label dynamic, I can't just insert the text from Photoshop.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Joey Morani
  • 25,431
  • 32
  • 84
  • 131

4 Answers4

19

You'll have to dynamically generate images representing your text if you want to anti-alias it. Here is an example on msdn: http://msdn.microsoft.com/en-us/library/a619zh6z.aspx

EDIT: Editing per comment below.

The link describes using the OnPaint event of your control to use a different TextRenderingHint. If you're wanting something a little more re-useable what you can do is create a Custom Label class that extends the Label class, and use this in your forms:

public partial class CustomLabel : Label
{
    private TextRenderingHint _hint = TextRenderingHint.SystemDefault;   
    public TextRenderingHint TextRenderingHint
    {
        get { return this._hint; }
        set { this._hint = value; }
    }        

    protected override void OnPaint(PaintEventArgs pe)
    {            
        pe.Graphics.TextRenderingHint = TextRenderingHint;
        base.OnPaint(pe);
    }
}

Add a new Custom Control called CustomLabel (or whatever you want to call it) and use the code above. Rebuild your project and you should then see the CustomLabel control appear in your toolbox at the top, under the "MyProject Components" category. In the properties pane for this custom label you'll see the new TextRenderingHint property. Set this to "AntiAlias." Add another label to your form and compare how they look.

If you want to default it to AntiAlias simply change the default value of the private variable.

Laurel
  • 5,965
  • 14
  • 31
  • 57
zincorp
  • 3,284
  • 1
  • 15
  • 18
  • Oh, sorry. I just dismissed your idea as somebody had downvoted it. How exactly would I use this? I keep getting errors when I try to compile it. – Joey Morani Apr 09 '10 at 20:34
  • 1
    The link overrides the OnPaint method to set the TextRenderingHint to AntiAlias. See my edit above on how you could use this in a reusable fashion. – zincorp Apr 09 '10 at 21:16
  • Thanks a lot! It works great. It's gone from looking like this "d-load.org/Capture.PNG" to looking like this "d-load.org/Capture2.PNG", just like your example. No idea why somebody downvoted you... Thanks again! – Joey Morani Apr 09 '10 at 21:39
5

Are you referring to ClearType? Then ClearType has to be enabled in Windows, and you must use a modern font, such as Tahoma or Segoe UI, not MS Sans Serif.

Update

You posted an example of the problem. I magnified it to 400 %. Clearly ClearType subpixel antialiasing is enabled. Personally I do not think the text looks jagged. If you want higer quality on-screen text you could buy a screen with a higher physical resolution (pixels per inch), and then draw the text at a (correspondingly) larger size. Then the text will have the same size on your screen, but will look much more smooth.

You could also give up on ClearType and use some other font-smoothing algorithm, but that is far from trivial, because ClearType is the font-smoothing system on Windows.

Update 2

If you are running Windows 7, you can fine-tune ClearType. Just open the start menu, write "ClearType" and start the guide. I think there are guides for Vista and XP too, but perhaps not installed by default, but available as PowerToys or something like that...

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • It's enabled. I tried it with Tahoma and Segoe UI, but it still looks jaggy. – Joey Morani Apr 09 '10 at 17:40
  • Okay, thanks. It's just other programs don't have jaggy text, with my current settings on ClearType. I'll change the settings on ClearType and see if it makes it any better. Thanks again. – Joey Morani Apr 09 '10 at 18:15
  • He had ClearType enabled. The problem is that with big fonts, cleartype looks bad. Why? Because it tries to make EVERYTHING sharp, and that sharpness looks like aliasing on fonts about 24+pt. – Camilo Martin Aug 27 '10 at 15:32
0

Make sure you have ClearType enabled.

xian
  • 4,657
  • 5
  • 34
  • 38
0

Install MacType program, it smoothes your Windows font like MacOS, I don't know why Microsoft don't fix its Windows smoothness font? If Microsoft fixed its fonts, I don't need to install third party app to such things like that which is fundamental for Windows.

Rebwar
  • 23
  • 4