UseCompatibleTextRendering property not created by designer when it is set to false

无人久伴 提交于 2019-12-11 06:38:57

问题


I do not wish to use compatible text rendering, but I do not wish to use

Application.SetCompatibleTextRenderingDefault(false);

Naturally, I thought all I had to do was set each label's UseCompatibleTextRendering property to false. The Forms Designer, however, apparently only generates code to set the property if UseCompatibleTextRendering is set to true.

No problem, I thought, that must mean that UseCompatibleTextRendering is initialized to false by default. Yet when I start up my form, lo and behold, I see ugly CompatibleTextRendering. So, a question:

1) Why on earth isn't the designer adding code for UseCompatibleTextRendering when I set it to false and it is when I set it to true, if the default is true?


回答1:


The designer does not add code for setting UseCompatibleTextRendering to false, because false is the default value.

So, why do the controls use compatible text rendering by default, if the default value of the property is false, that seems to be... odd? Well, the Application.SetCompatibleTextRenderingDefault method assigns the given value to a static field in the Control class, and the static constructor of the Control class initializes this field to true.

So, removing the line Application.SetCompatibleTextRenderingDefault(false); will cause the application to use compatible text rendering, contrary to what you might think based on the default value of the UseCompatibleTextRendering property.

The only reasonable solution that I can see is to simply leave the automatically generated call to Application.SetCompatibleTextRenderingDefault where it is.




回答2:


The problem occured in an Com-Interop-DLL I wrote for use within Microsoft Excel.

The DLL is written in VB.NET and contains a Form that is shown from within Excel.

Now, the Excel.Application sets the UseCompatibleTextRendering to true by default. Therefore all labels and buttons of the form render poorly if the DLL is embedded in Excel (GDI+-Graphics-Class) but perfectly right from within any .Net-Windows Application.

To correct this, I had to loop over all labels and buttons and set the UseCompatibleTextRendering to false on Form.Load event. I found no way to use the SetCompatibleTextRenderingDefault neither within the DLL nor within Excel.



来源:https://stackoverflow.com/questions/1296951/usecompatibletextrendering-property-not-created-by-designer-when-it-is-set-to-fa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!