是否可以将 TextRenderingHint 设置为用于整个应用程序?
我想在 C# 应用程序中使用抗锯齿字体。我已阅读此处 如何使用 Paint 事件完成每个表格:
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);
}
}
这可能会很麻烦,因为我们已经完成了很多表格。此外,在每种表单中,我们都使用多种表单类型。 TextRenderingHint
的设置可以全局设置吗?
编辑1
引用的示例,尽管它已经过时,正如nobugz,帮助我认识到在这个系统中使用的最好的 TextRenderingHint
是 AntiAliasGridFit
。硬件平台是封闭的,所以我可以保证这是该系统的最佳配置,对于将要部署该应用程序的所有系统来说也是最佳的。
我可以在任何地方设置 TextRenderingHint
的默认设置吗?我正在 Windows Embedded Standard(以前的 Windows XP Embedded)映像中运行该应用程序。
编辑2
我发现在XP系统中你可以设置注册表默认使用的TextRenderingHint
类型。它不是按应用程序方法,而是按用户方法。注册表项是:
HKCU\Control Panel\Desktop\FontSmoothing {2 for activating font smoothing}
HKCU\Control Panel\Desktop\FontSmoothingType {1 for Antialiasing, 2 for ClearType}
感谢支持!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您链接的文章既不相关又过时。 ClearTypeGridFit 已经是启用 ClearType 的计算机上的默认抗锯齿绘图模式。并且您应该使用 TextRenderer 类进行文本渲染,Graphics.DrawString() 有问题。
您可以使用 SysInternals 的 ZoomIt 实用程序仔细检查是否获得了 ClearType 抗锯齿功能。放大时,您应该能够看到沿着字体轮廓绘制的微红色和蓝色边缘。
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.
如果稍后不打印,您可以使用 TextRenderer 来使用 GDI 文本呈现。否则,只需使用具有 DrawText 方法的类似类,以 Graphics 作为参数,并在每次调用时设置渲染提示
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