Search code examples
c#.netwinformsfontsopentype

"Windows Forms" seems to support OTF-Fonts. But why does it work, when everyone else says the opposite?


I thought that "Windows Forms" doesn't support OTF-Fonts. But by trying it anyways I realized the opposite.

  1. I just created a new "Windows Forms" project, which uses the ".NET Framework 4.8" and C# (later I made the same in VB.NET).
  2. I set a label and a button in a brand new form.
  3. I made the click event of the button open an instance of the class "System.Windows.Forms.FontDialog" and set the font of the label by the chosen font. Then I started the application, clicked on the button, chose my installed OTF-Font and looked on the result.

For me it works perfectly well, but why, when everyone says that OTF-Fonts are not supported in "Windows Forms"? I also tried different OTF-Fonts and also checked multiple times if they’re actually OTF-Fonts and it still works. And I also tried this "Windows Forms"-Application and the OTF-Fonts on a brand new virtual machine. It still works.

Has anyone an idea, what I’ve perhaps have done different than everyone else?

The reason I asked this question is that someone I know has the problem that a "Windows Forms"-Application crashes with the exception message, that only TTF-Fonts are supported, every time an OTF-Font was chosen. And I'm unable to reproduce this issue in my environment and can use OTF-Fonts in an "Windows Forms"-Application without any problems, but don't know, why.


Solution

  • This problem can be reproduced by installing a Font in runtime of the program before he tried to use it.

    The message that the OTF-Format was to blame (only the TTF-Format will be accepted) occured but the true reason was the installation or the way how the font was installed.

    The same with the installation of the TTF-Fonts (with the same error message).

    So when something with the installation of the Font went wrong the exception happens and the occurring error message is misleading.