【问题标题】:RichTextBox incorrect behavoir with private fontsRichTextBox 使用私有字体时行为不正确
【发布时间】:2012-06-12 09:59:34
【问题描述】:

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

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 我也在使用我的私有字体?

【问题讨论】:

    标签: c# fonts richtextbox


    【解决方案1】:

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

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

    如果 familyName 参数指定的字体未安装在 运行应用程序的机器或不受支持,Microsoft Sans Serif 将被替换

    【讨论】:

      猜你喜欢
      • 2012-10-05
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 2012-04-16
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      相关资源
      最近更新 更多