C# 透明.NET格式的抗锯齿文本
我有一个C#应用程序,它在一个表中显示当前时间 透明的.NET表单。表单没有控件,也没有边框。 其属性TransparencyKey设置为窗体的背景色 “浅灰色”使其透明。C# 透明.NET格式的抗锯齿文本,c#,.net,winforms,C#,.net,Winforms,我有一个C#应用程序,它在一个表中显示当前时间 透明的.NET表单。表单没有控件,也没有边框。 其属性TransparencyKey设置为窗体的背景色 “浅灰色”使其透明。 因此,用户只能看到文本(当前时间) 文本在PaintEventHandler中绘制: private void Display_Paint( object sender, PaintEventArgs e ) { Graphics formGraphics = e.Graphics; Font myFont
因此,用户只能看到文本(当前时间) 文本在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();
}
由于抗锯齿功能,当
形式是在一个黑暗的背景。对于浅色背景,文本没有问题
此图显示了问题和良好情况:
(来源:) 显然,Windows确实以适合用户的方式呈现文本 窗体自身的背景色,而不是以适合 透明窗体后面的背景 有没有可能让Windows来处理背景 在呈现文本时要考虑表单,以便 去除流苏 一个“解决方案”是通过设置TextRenderingHint来关闭抗锯齿 因此。但到目前为止,这并不是我喜欢的“解决方案” 系统:
Windows XP,SP 3,.NET 3.5,VS 2008几个月前我问过 我最后做的是有两个选择:
在“显示\绘制”方法中,尝试以下操作:
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
谢谢你的提示,但是设置样式没有帮助。我想知道更多关于复制部分的信息。实际上我做了一些搜索,似乎我在寻找CopyFromScreen,