gpt4 book ai didi

c# - RichTextBox 使用私有(private)字体的不正确行为

转载 作者:行者123 更新时间:2023-11-30 22:28:07 27 4
gpt4 key购买 nike

使用带有私有(private)字体的 RichTextBox 我遇到了以下问题:我可以在文本框中使用我的私有(private)字体编写文本,但是当我选择它时(在我的程序中需要它)文本框返回 MS Sans Serif 作为选择字体。

PrivateFontCollection pfc = new PrivateFontCollection(); // font collection
pfc.AddFontFile("..\\..\\Fonts\\infotra1.ttf"); // load font
rtb.Font = new Font(pfc.Families[0], 10.0f, FontStyle.Regular);
rtb.AppendText("lorem ipsum bla bla bla\n");

现在,文本已正确附加到文本框中。

private void rtb_SelectionChanged(object sender, EventArgs e) { var f = rtb.SelectionFont; }

如果我选择文本并检查 rtb.SelectionFont,它会返回 MS Sans Serif。

我知道系统在找不到我的字体时会返回 MS Sans Serif。我是否应该以某种方式告诉 RichTextBox 我也在使用我的私有(private)字体?

最佳答案

它可能按预期工作,但您需要查看 f.OriginalFontName 而不是 f.Name 才能实现它,因为您使用的是私有(private)字体。

查看字体文档 (http://msdn.microsoft.com/en-us/library/164w6x6z) 我发现了这个:

If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

关于c# - RichTextBox 使用私有(private)字体的不正确行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10947209/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com