设置为false时,UseCompatibleTextRendering属性不是由设计者创建的

xof*_*ofz 1 c# windows-forms-designer winforms

我不希望使用兼容的文本呈现,但我不想使用

Application.SetCompatibleTextRenderingDefault(false);
Run Code Online (Sandbox Code Playgroud)

当然,我认为我所要做的就是将每个标签的UseCompatibleTextRendering属性设置为false.但是,如果UseCompatibleTextRendering设置为true,则表单设计器显然只生成用于设置属性的代码.

我认为没问题,这必定意味着默认情况下UseCompatibleTextRendering被初始化为false.然而,当我启动我的表格时,我看到丑陋的CompatibleTextRendering.所以,一个问题:

1)为什么地球上不是设计师添加代码UseCompatibleTextRendering当我把它设置为false,这当我把它设置为true,如果默认是真的吗?

Fre*_*örk 5

设计者没有设置代码添加UseCompatibleTextRenderingfalse,因为false是默认值.

那么,为什么控件默认使用兼容的文本呈现,如果属性的默认值是false,那似乎是......奇怪的?好吧,该Application.SetCompatibleTextRenderingDefault方法将给定值分配给Control类中的静态字段,Control类的静态构造函数将此字段初始化为true.

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

我能看到的唯一合理的解决方案就是将自动生成的调用留Application.SetCompatibleTextRenderingDefault在原来的位置.