c# - UseCompatibleTextRendering 属性在设置为 false 时不是由设计器创建的

标签 c# winforms windows-forms-designer

我不想使用兼容的文本渲染,但我不想使用

Application.SetCompatibleTextRenderingDefault(false);

当然,我认为我所要做的就是将每个标签的 UseCompatibleTextRendering 属性设置为 false。但是,如果 UseCompatibleTextRendering 设置为 true,Forms Designer 显然只会生成代码来设置属性。

没问题,我想,这一定意味着 UseCompatibleTextRendering 默认初始化为 false。然而,当我启动我的表单时,你瞧,我看到丑陋的 CompatibleTextRendering。所以,一个问题:

1) 当我将 UseCompatibleTextRendering 设置为 false 时,为什么设计师不添加代码,而当我将它设置为 true 时,它​​,如果默认为 true?

最佳答案

设计者没有添加设置UseCompatibleTextRendering的代码至 false ,因为 false是默认值。

那么,如果属性的默认值为false,为什么控件默认使用兼容的文本渲染呢? ,那好像……很奇怪?嗯,Application.SetCompatibleTextRenderingDefault方法将给定值赋给Control类中的一个静态字段,Control类的静态构造函数将这个字段初始化为true。 .

因此,删除行 Application.SetCompatibleTextRenderingDefault(false);将导致应用程序使用兼容的文本呈现,这与您基于 UseCompatibleTextRendering 的默认值可能会想到的相反属性(property)。

我能看到的唯一合理的解决方案是简单地将自动生成的调用留给 Application.SetCompatibleTextRenderingDefault它在哪里。

关于c# - UseCompatibleTextRendering 属性在设置为 false 时不是由设计器创建的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1296951/

相关文章:

c# - 限制同时发出的 Web 服务请求数

c# - Visual Studio Shell 14 升级破坏了 VSPackage 中的命令捕获

c# - 我怎样才能把一个进程句柄窗口放在前面,但在正常大小下不能最大化?

c# - 如何在 C# 程序的面板中运行另一个应用程序?

c# - 在设计器中删除 GenerateMember 和 Modifiers 属性

c# - 引用变量内部结构

c# - WMI : Getting Interface Name, 状态网络

c# - 为什么 xmlDocument.Select 返回零计数

c# - 如何使停靠面板越过另一个停靠面板

WinForms 设计器异常