我有一个C#应用程序,它以透明的.NET表单显示当前时间.表格没有控件也没有边框.其属性TransparencyKey设置为Form的背景颜色"浅灰色",使其透明.
因此用户只能看到文本(当前时间).
该文本在PaintEventHandler中绘制:
private void Display_Paint( object sender, PaintEventArgs e )
{
Graphics formGraphics = e.Graphics;
Font myFont = new Font( "Microsoft Sans Serif", 24, FontStyle.Bold );
formGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
//formGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
formGraphics.DrawString( "00:00:00", myFont, Brushes.Green, 0.0F, 0.0F );
myFont.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
由于抗锯齿,当表格在黑暗背景下时,文本"00:00:00"显示为磨损.对于浅色背景,文字没问题
此图显示了问题和好的情况:
文字显示由于深色背景的抗锯齿而产生的条纹http://www.habermann-net.de/public/development/antiAliasing_bad.png
显然,Windows确实以适合Form自身背景颜色的方式呈现文本,而不是以适合透明Form背后的背景的方式呈现文本.
是否有可能让Windows在渲染文本时考虑到Form背后的背景,以便摆脱边缘?
一个"解决方案"可能是通过相应地设置TextRenderingHint来关闭抗锯齿.但到目前为止,这不是我首选的"解决方案".
系统:
Windows XP,SP 3,.NET 3.5,VS 2008