Dan Tumaykin
Dan Tumaykin

Reputation: 1253

RichTextBox incorrect behavoir with private fonts

Using RichTextBox with private fonts I've encountered following problem: I'm able to write the text with my private font inside the text box, but when I select it(need it further in my program) text box return MS Sans Serif as Selection font.

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");

Now, text is correctly appended into the text box.

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

If I select the text and inspect rtb.SelectionFont it returns MS Sans Serif.

I know that system returns MS Sans Serif when it's unable to find my font. Should I tell to RichTextBox in some way that I'm using also my private fonts?

Upvotes: 2

Views: 646

Answers (1)

zeFrenchy
zeFrenchy

Reputation: 6591

It is probably working as expected but you need to look at f.OriginalFontName instead of f.Name to realise it since you are using private fonts.

Looking into the Font Documentation ( http://msdn.microsoft.com/en-us/library/164w6x6z ) I found this:

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.

Upvotes: 3

Related Questions