Rich text box replaces default Monospaced font for Box-drawing characters with Variable-width font

213 Views Asked by At

I have a Windows rich text box control (RichTextBox) on my form. The box has Consolas monospaced font set. For most contents the box indeed renders it with the selected font. But when I load/set contents with Box-drawing characters, the box renders them with variable-width font (Segoe UI Symbol). What defies the very purpose of those characters.

Simple example:

private void InitializeComponent()
{
    // ...
    this.richTextBox1 = new System.Windows.Forms.RichTextBox();
    this.richTextBox1.Font =
       new System.Drawing.Font("Consolas", 12F, System.Drawing.FontStyle.Regular,
                               System.Drawing.GraphicsUnit.Point, ((byte)(0)));
   this.richTextBox1.Location = new System.Drawing.Point(45, 34);
   this.richTextBox1.Name = "richTextBox1";
   this.richTextBox1.Size = new System.Drawing.Size(533, 318);
   this.richTextBox1.TabIndex = 0;
   this.richTextBox1.Text =
       "╔════════════════════════════════════════════════╗\n" +
       "║                 This is a test                 ║\n" +
       "╚════════════════════════════════════════════════╝";
    // ...
}

Results in:
enter image description here

If I copy-paste the contents to e.g. Microsoft Word, I can see that only this parts has the Consolas font:
This is a test
The rest (all the Box-drawing characters) has Segoe UI Symbol font.

What I can I do to prevent RichTextBox from replacing the font?

My search resulted only in this article:
https://devblogs.microsoft.com/math-in-office/richedit-font-binding/
But it says that Rich text box replaces font only for characters that are not supported by the font. I'm sure that Consolas does support Box-drawing characters.

0

There are 0 best solutions below