2 years ago

#13828

test-img

HimmDawg

RichTextBox having problems replacing Cambria Math font

In my WinForms program, I have a rtf text. It contains this char '≈'. The problem is, that '≈' always has the font Cambria Math which is not supported by another part of the program. So i want to replace the font for this char to Arial since this font is supported. Therefore I try to do this:

for (int i = 0; i < this.rtfBox.Text.Length; i++)
{
      this.rtfBox.Select(i, 1);

      if (this.rtfBox.SelectionFont != null && this.rtfBox.SelectionFont.FontFamily.Name == "Cambria Math")
      {
            this.rtfBox.SelectionFont = new Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Point, 2);
      }
}

Replacing the font works at first glance. The font of '≈' indeed changes but the problem occurs when I save this rtf and reload it. The '≈' suddenly becomes a captial 'H'. When I check the rtf itself, the char is indeed just an H.

Anything I can do?

c#

winforms

fonts

richtext

0 Answers

Your Answer

Accepted video resources