SetCompatibleTextRenderingDefault in a .NET class library containing a form

I have a .net class library with a com class that invokes a form. I want SetCompatibleTextRenderingDefault(false) to make the font form look good.

If I run the command in the class constructor, I get the following error: SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.

Where can i run this? Of course there is no earlier place than south New!

thanks in advance

John

Edit1: To clarify, I get this error when starting the class from the test .net bundle, if I call it from the VB6 application, then I just get the message โ€œAutomation errorโ€

Edit2: Answer that I cannot use SetCompatibleTextRenderingDefault in class com when called from a vb6 application? Maybe this is the "parent" application that needs to call this method, and as such, the vb6 application cannot?

Edit3: Perhaps I am asking this question wrong! - Perhaps the question is this: how to make fonts look beautiful in the form of a .net class library called from a vb6 application?

+4
source share
2 answers

A possible workaround would be to set the property manually for all buttons and labels in the form designer:

 public Form1() { InitializeComponent(); DisableCompatibleTextRendering(this); } private static void DisableCompatibleTextRendering(Control c) { var button = (c as ButtonBase); var label = (c as Label); if (button != null) { button.UseCompatibleTextRendering = false; } if (label != null) { label.UseCompatibleTextRendering = false; } foreach (var child in c.Controls.Cast<Control>()) { DisableCompatibleTextRendering(child); } } 
+2
source

Put this in the application launch code before creating the first window. In C #, this will be the main procedure, which then creates the initial window.

0
source

All Articles