views:

526

answers:

3

Hello. 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. Any idea? Thanks.

+4  A: 

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
It's enabled. I tried it with Tahoma and Segoe UI, but it still looks jaggy.
Joey Morani
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
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
A: 

Make sure you have ClearType enabled.

kitchen
+3  A: 

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.

Here is the resulting comparison between two Labels, one with the default TextRenderingHint and one with it set to AntiAlias: http://www.freeimagehosting.net/uploads/a8e533c7b6.png

zincorp
Why was this downvoted? He asked how to dynamically generate "smooth" text in a C# winform and I linked an article explaining how to accomplish that.
zincorp
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
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
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