简体   繁体   English

System.Drawing.Font 未按预期工作

[英]System.Drawing.Font not working as expected

I'm trying to use a private font (PrivateFontCollection) to change a RichTextBox font.我正在尝试使用私有字体 (PrivateFontCollection) 来更改 RichTextBox 字体。 The problem is, the program recognizes the font when I pass the path to it but, when I change the RTB font, it doesn't work and instead it uses Calibri .问题是,当我将路径传递给程序时,程序会识别字体,但是当我更改 RTB 字体时,它不起作用,而是使用Calibri

The code is very simple:代码非常简单:

var RTB = new System.Windows.Forms.RichTextBox();

var privateFont = new System.Drawing.Text.PrivateFontCollection();
privateFont.AddFontFile(@"path.ttf");

RTB.SelectAll();
RTB.SelectionFont = new System.Drawing.Font(privateFont.Families[0], 12);

I'm using it to format a RTF text file.我正在使用它来格式化 RTF 文本文件。 When I generate the file it comes out with the Calibri font.当我生成文件时,它带有 Calibri 字体。 And what intrigues me the most is, if I change the privateFont.AddFontFile(@"path.ttf");最让我感兴趣的是,如果我更改privateFont.AddFontFile(@"path.ttf"); to Arial , for example, the text is returned in the font I wanted, but not the whole text, the end of the text is returned in Calibri .Arial为例,文本以我想要的字体返回,但不是整个文本,文本的结尾以Calibri返回。

I don't know what is happening here.我不知道这里发生了什么。

["

To answer your question of "what is happening here", for a font to be recognized in an exported RTF file requires that the font either be installed as a system font or<\/em> manually embedded in the file that you are exporting from the RichTextBox<\/code> .<\/i>要回答“这里发生了什么”的问题,要在导出的 RTF 文件中识别字体,需要将该字体作为系统字体安装或<\/em>手动嵌入到您从RichTextBox<\/code>导出的文件中。<\/b> The former seems less dicey and the three ways I know of to make the font be installed are:<\/i>前者似乎不那么冒险,我知道的三种安装字体的方法是:<\/b><\/p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM