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

huangapple go评论75阅读模式
英文:

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

问题

我曾以为“Windows Forms”不支持OTF字体。但尝试后,我发现情况相反。

  1. 我刚刚创建了一个使用“.NET Framework 4.8”和C#(后来我也在VB.NET中尝试了相同的操作)的新“Windows Forms”项目。
  2. 我在一个全新的窗体中设置了一个标签和一个按钮。
  3. 我在按钮的单击事件中打开了一个“System.Windows.Forms.FontDialog”类的实例,并通过选择的字体设置了标签的字体。
    然后我启动了应用程序,点击按钮,选择了我安装的OTF字体,并查看了结果。

对我来说,它完美地工作,但为什么每个人都说“Windows Forms”不支持OTF字体呢?
我还尝试了不同的OTF字体,并多次检查它们是否确实是OTF字体,它仍然能够正常工作。
我还在全新的虚拟机上尝试了这个“Windows Forms”应用程序和OTF字体。它仍然可以正常工作。

有人知道我可能做了什么与其他人不同的事情吗?

我提出这个问题的原因是,我认识的某人在选择OTF字体后,一个“Windows Forms”应用程序崩溃,并显示只支持TTF字体的异常消息。但在我的环境中,我无法重现这个问题,并且可以在“Windows Forms”应用程序中使用OTF字体而没有任何问题,但我不知道为什么。

英文:

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.

答案1

得分: 0

这个问题可以通过在程序运行时安装字体,然后再尝试使用它来复现。

出现了OTF格式有问题的消息(只有TTF格式会被接受),但真正的原因是字体的安装或安装方式

安装TTF字体时也会出现相同的错误消息。

因此,当字体安装出现问题时,会引发异常,出现的错误消息会误导。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月6日 18:23:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76627834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定