Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 透明.NET格式的抗锯齿文本_C#_.net_Winforms - Fatal编程技术网

C# 透明.NET格式的抗锯齿文本

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

我有一个C#应用程序,它在一个表中显示当前时间 透明的.NET表单。表单没有控件,也没有边框。 其属性TransparencyKey设置为窗体的背景色 “浅灰色”使其透明。
因此,用户只能看到文本(当前时间)

文本在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

几个月前我问过

我最后做的是有两个选择:

  • 通过将不透明度临时设置为0,复制应用程序后面的背景,然后在该背景上绘制抗锯齿文本。如果窗口及其下的窗口不经常移动,这种方法效果很好
  • 使用。与透明键相比效果更好,但对于非抗锯齿文本仍然效果最好。(只要避免使用ClearType字体,你就会没事的)

  • 在“显示\绘制”方法中,尝试以下操作:

    this.SetStyle(ControlStyles.DoubleBuffer | 
          ControlStyles.UserPaint | 
          ControlStyles.AllPaintingInWmPaint,
          true);
    this.UpdateStyles();
    

    谢谢你的提示,但是设置样式没有帮助。我想知道更多关于复制部分的信息。实际上我做了一些搜索,似乎我在寻找CopyFromScreen,