Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong font displayed at runtime

Tags:

c#

winforms

fonts

I am using the Calibri font in some labels (winforms) and when I run my program, this label are displayed with a different font. I had seen this problem when testing on computers without Office (hence no Calibri installed) but now I see it everywhere, even on my computer where Calibri is well installed (and I see the labels with Calibri in the designer ; then when I run in debug mode, I see another font).

The labels used to be displayed well, I've seen this problem only today (but could have been unnoticed for a few days, I'm not sure, but not long, that I'm sure).

There were a few windows updates yesterday, and some were for Office, but I'm not sure if it's relevant. Bottomline is I have calibri, calibri is displayed in designer, and some other font is displayed at runtime.. And I seem to have the same problem with Segoe UI, but only when using the SemiBold style..

Here is an image of the result, on the left is runtime and on the right is the VS designer:

Left is runtime, right is designer

It is even more obvious when I try to use Calibri bold ; this time runtime is on the right and designer view on the left :

Left for designer, right for runtime

like image 894
Mickael V. Avatar asked Dec 05 '12 15:12

Mickael V.


1 Answers

Whenever you create a new Windows Forms application in Visual Studio, the template includes the following lines

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(/*new instance of your form*/);

This line in particular will likely affect how text is rendered in your application.

Application.SetCompatibleTextRenderingDefault(false);
like image 125
Matthew Layton Avatar answered Oct 19 '22 22:10

Matthew Layton