Reputation: 5660
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?
Upvotes: 1
Views: 3785
Reputation: 31
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.
Upvotes: 3
Reputation: 158379
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.
Upvotes: 5