-1

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.

GeoMH
  • 39
  • 6
  • 1
    Note, I may be wrong: when you select a Font from the dialog, under the hood it uses `ChooseFont()` to present the dialog. This function returns a LOGFONTW struct that is then fed to `GdipCreateFontFromLogfontW()`. At run-time, the Screen DC is used as device context. This may imply that Windows' ClearType has its say on how the LOGFONT struct is filled, so the status returned by the GDI+ function is not `16` (Not a True Type Font), because it can actually use this struct to build the Font – Jimi Jul 06 '23 at 12:55
  • 1
    BTW, see here: [How to set the SelectedValue of a ComboBox used as Font selector?](https://stackoverflow.com/a/62076757/7444103): not all those Fonts are TTFs, a couple of them are OTF (OTF Layout, TrueType outlines), one is OTF Postscript Layout – Jimi Jul 06 '23 at 13:03
  • 1
    "And I'm unable to reproduce this issue in my environment" with _their_ code, or with your _own_ code? Because reproduction means you run the exact same code. – Mike 'Pomax' Kamermans Jul 13 '23 at 16:43
  • I’m voting to close this question because the poster seems to have abandoned it. – Mike 'Pomax' Kamermans Jul 26 '23 at 04:17
  • Sorry for answering so late. Too much to do. We 're talking about one single program (one code). Meanwhile one of my co-workers managed to reproduce this issue by installing a Font in runtime of the program before he tried to use it. The message that the OTF-Format was to blame occurred but the true reason was the installation or the way how the font was installed. I guess that this reason was also the reason in the beginning. – GeoMH Jul 31 '23 at 13:02

1 Answers1

0

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.

GeoMH
  • 39
  • 6
  • This does not make sense to an English (or English as second language) reader. Please rephrase this so that it's clear what the actual problem was, what the solution was, and why that solution worked. Without bold text. While the edit box lets you bold text, there is never a reason to use bold text in a post. Code markup, absolutely, headings, sometimes, bold text, never. – Mike 'Pomax' Kamermans Aug 07 '23 at 05:10