Click here to Skip to main content
15,849,829 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

recently I am having some problems with a RichTextBox displaying Unicode characters, especially arabic, when the font used is Verdana.
However, displaying the same content on a Label or TextBox shows good and correct results. Also when using Microsoft Sans Serif instead of Verdana.

Is anyone having an idea how to solve? You can take the following as an example input for the Text property of either control:

b, t, th, dsch, h´, ch, d, th, r, z, ß, sh, s, d, t, th, a, r, f, q, k, l, m, n, h, w(u), y(i)
ﺃ, ﺐ, ﺕ, ﺚ, ﺝ, ﺡ, ﺥ, ﺪ, ﺫ, ﺭ, ﺯ, ﺱ, ﺵ, ﺹ , ﺽ, ﻁ , ﻅ, ﻉ, ﻍ, ﻑ, ﻕ, ﻙ, ﻝ, ﻡ, ﻥ, ﻩ, ﻭ, ﻱ

On a RichTextBox using Verdana the arabic characters will be displayed as squares. You can also try the following code:

using System.Windows.Forms;
namespace RichTextBoxDoesNotUnderstandArabic
    public partial class Form1 : Form
        public Form1()
            string unicodeText = "a, b, t, th, dsch, h´, ch, d, th, r, z, ß, sh, s, d, t, th, a, r, f, q, k, l, m, n, h, w(u), y(i) ﺃ, ﺐ, ﺕ, ﺚ, ﺝ, ﺡ, ﺥ, ﺪ, ﺫ, ﺭ, ﺯ, ﺱ, ﺵ, ﺹ , ﺽ, ﻁ , ﻅ, ﻉ, ﻍ, ﻑ, ﻕ, ﻙ, ﻝ, ﻡ, ﻥ, ﻩ, ﻭ, ﻱ";
            // richTextBox1
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.richTextBox1.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (0)));
            this.richTextBox1.Location = new System.Drawing.Point(25, 80);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(260, 103);
            this.richTextBox1.TabIndex = 0;
            this.richTextBox1.Text = unicodeText;
            // label1
            this.label1 = new System.Windows.Forms.Label();
            this.label1.BackColor = System.Drawing.Color.White;
            this.label1.Font = new System.Drawing.Font("Verdana", 8.25F);
            this.label1.Location = new System.Drawing.Point(309, 80);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(260, 103);
            this.label1.TabIndex = 1;
            this.label1.Text = unicodeText;
            // textBox1
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox1.Font = new System.Drawing.Font("Verdana", 8.25F);
            this.textBox1.Location = new System.Drawing.Point(591, 80);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(260, 103);
            this.textBox1.TabIndex = 2;
            this.textBox1.Text = unicodeText;
            // Form1
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(883, 222);
            this.Name = "Form1";
            this.Text = "Form1";

Best regards,

Sound like the font doesn't not include the required characters. Not all fonts support all unicode code points.

Espen Harlinn
Share this answer
Sergey Alexandrovich Kryukov 21-Jan-11 14:48pm    
As easy as that -- I checked up.
can done in VB.NET
RichTextBox1.Text = (System.Text.RegularExpressions.Regex.Replace(str, "(\d{3,}?);", New System.Text.RegularExpressions.MatchEvaluator(AddressOf ConvertCode)))

Just Convert this in C or C# by this site

Convert Code Site

Share this answer
Thomas Daniels 13-Nov-12 12:45pm    
Why you don't post the converted code, instead of posting VB.NET code and telling the OP that he need to convert it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900