I cannot get WinForms RichTextBox
display some Unicode characters, particularly Mathematical alphanumeric symbols (but the problem is most probably not limited to those).
Surprisingly the same characters can display in a plain or multiline TextBox
using the same (default) font. Even if I change the font to for example "Arial" or "Lucida", I get the same results.
The screenshot is from Windows 10, but I'm getting the same results on Windows 7. The example shows ascii small a-d followed by mathematical italic sans-serif small alpha-delta.
I'm using Visual Studio 2017 and .NET 4.6.1.
A trivial test code:
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
// ...
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(25, 38);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(182, 108);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "abcd πΌπ½πΎπΏ";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(213, 38);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(179, 108);
this.richTextBox1.TabIndex = 1;
this.richTextBox1.Text = "abcd πΌπ½πΎπΏ";
// ...
}
Note that it does not seem to be a problem with storing the characters. The characters are correctly stored in the RichTextBox
. If you copy the text out and paste it somewhere (like to the TextBox
), all characters display correctly.
On the other hand, if you paste the characters to the RichTextBox
, you get the same incorrect display.
So it looks like a display problem only.
It's a bug/decision by design in RichTextBox
which has been fixed in .NET 4.7.
RichTextBox
is in fact a wrapper around RichEdit
. In .NET 4.7, the control is using RICHEDIT50W
while in previous versions it's using RichEdit20W
.
To solve the problem you can use either of these options:
OR
RichTextBox
that is RICHEDIT50W
, to do so you should inherit from standard RichTextBox
and override CreateParams
and load library Msftedit.dll
and set the ClassName
to RICHEDIT50W
. To see an implementation, take a look at this post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With