Wrong font displayed at runtime

☆樱花仙子☆ 提交于 2021-02-07 12:05:17

问题


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


回答1:


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);


来源:https://stackoverflow.com/questions/13726733/wrong-font-displayed-at-runtime

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