c# - 透明表单无法正确显示文本

发布于 2024-12-20 19:12:11 字数 258 浏览 1 评论 0原文

我的项目的想法是在透明表单控件上显示纯文本。

我已经使用这种技术使表单透明:

BackColor = Color.Lime;
TransparencyKey = Color.Lime;

我遇到的问题是文本周围的彩色边缘。我尝试过使用图形绘制抗锯齿文本并使用标签显示文本,但都不起作用。我的文字周围仍然有看起来很恶心、像素化、石灰质的边缘。

我环顾四周 - 帖子通常关注的是使表单透明而不是处理这个问题。

The idea of my project is to show solid text on a transparent form control.

I have used this technique to make the form transparent:

BackColor = Color.Lime;
TransparencyKey = Color.Lime;

The problem I'm having is coloured edges around the text. I've tried drawing anti-aliased text using graphics and displaying the text using labels but neither worked. I still have disgusting-looking, pixelated, lime edges around my text.

I looked around a little - posts are usually concerned with making the form transparent not dealing with this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻梦 2024-12-27 19:12:11

您可以使用 TextRenderingHint.AntiAliasGridFit 获得合理输出。

private void TestForm_Paint(object sender, PaintEventArgs e) {
  e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
  e.Graphics.DrawString("Header", this.Font, SystemBrushes.WindowText, new Point(1, 1));
}

但如果您打算使用大字体,它的渲染效果就不会太好,因为它无法真正正确地抗锯齿

一般来说,字体的本质是有一个可以绘制的背景。如果透明表单上有黑色文本,并且最终用户有黑色背景,则最终用户将看不到任何内容。

You can get reasonable output by using TextRenderingHint.AntiAliasGridFit.

private void TestForm_Paint(object sender, PaintEventArgs e) {
  e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
  e.Graphics.DrawString("Header", this.Font, SystemBrushes.WindowText, new Point(1, 1));
}

But if you plan on using large fonts, it won't render too well since it can't really antialias properly.

The nature of fonts, in general, is to have a background to draw on. If you have black text on a transparent form, and the end user has a black background-- the end user isn't going to see anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文