Is possible to set the TextRenderingHint to be used for a whole application?
I wanto to use antialiased fonts in a C# application. I have read here how can be done with the Paint event of each form:
public class SmoothingFonts : System.Windows.Forms.Form
{
...
private void 开发者_高级运维InitializeComponent()
{
...
this.Paint += this.SmoothingFonts_Paint;
}
private void SmoothingFonts_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Font TextFont = new Font("Verdana", 25, FontStyle.Italic);
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
e.Graphics.DrawString("Sample Text", TextFont, Brushes.Black, 20, 150);
}
}
This could get cumbersome because we already have many forms done. Also, in every form we use several forms types. Can the setting for TextRenderingHint
be set globally?
EDIT 1
The example cited, eventhough it's outdated as correctly pointed by nobugz, helped me to realise that the best TextRenderingHint
to be used in this system is AntiAliasGridFit
. The hardware platform is closed, so I can assure that it is the best configuration for this system will be the best for all the systems where the application will be deployed.
Can I set the default setting for the TextRenderingHint
anywhere? I'm running the application in a Windows Embedded Standard (former Windows XP Embedded) image.
EDIT 2
I found that in a XP system you can set the type of TextRenderingHint
used by the default by the registry. It is not a by application method, but a by user method. The registry keys are:
HKCU\Control Panel\Desktop\FontSmoothing {2 for activating font smoothing}
HKCU\Control Panel\Desktop\FontSmoothingType {1 for Antialiasing, 2 for ClearType}
Thanks for the support!
The article you linked manages to be both irrelevant and outdated. ClearTypeGridFit is already the default anti-aliasing drawing mode on machines that have ClearType enabled. And you should use the TextRenderer class for text rendering, Graphics.DrawString() has problems.
You can double-check that you are getting ClearType anti-aliasing by using SysInternals' ZoomIt utility. You should be able to see the reddish and bluish fringes drawn along the font outline when you zoom in.
You can use GDI text rendering using TextRenderer if not printing it later. Other wise just right a similar class with a DrawText method with take Graphics as parameter and sets rendering hint everytime it is called
TextRenderer.DrawText( e.Graphics,
"Text",
font,
textRect,
ForeColor,
BackColor
);
精彩评论