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

2

1

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?

Lananna answered 18/8, 2009 at 22:36 Comment(0)
C
5

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.

Carbarn answered 19/8, 2009 at 7:45 Comment(1)
Thanks. Why Control.UseCompatibleTextRenderingDefault is initialized to true baffles me.Lananna
P
3

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.

Publius answered 19/8, 2014 at 15:14 Comment(2)
Edit: The same happens if You create a Console Application and reference the DLL to show a windows form.Publius
There is a note that you can't change it parent application sets it (for a first WinForm) here: learn.microsoft.com/en-us/dotnet/api/… Exceptions InvalidOperationException You can only call this method before the first window is created by your Windows Forms application.Duwe

© 2022 - 2024 — McMap. All rights reserved.