Click here to Skip to main content
12,953,491 members (52,832 online)
Rate this:
Please Sign up or sign in to vote.

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,
Posted 21-Jan-11 1:16am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

Espen Harlinn
SAKryukov 21-Jan-11 14:48pm
As easy as that -- I checked up.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

ProgramFOX 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,930

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100