Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
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) ﺃ, ﺐ, ﺕ, ﺚ, ﺝ, ﺡ, ﺥ, ﺪ, ﺫ, ﺭ, ﺯ, ﺱ, ﺵ, ﺹ , ﺽ, ﻁ , ﻅ, ﻉ, ﻍ, ﻑ, ﻕ, ﻙ, ﻝ, ﻡ, ﻥ, ﻩ, ﻭ, ﻱ";
            this.SuspendLayout();
            //
            // 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.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.richTextBox1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();
        }
    }
}
 
Best regards,
Michael
Posted 21-Jan-11 2:16am
Rate this: bad
good
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.
 
Regards
Espen Harlinn
  Permalink  
Comments
SAKryukov at 21-Jan-11 14:48pm
   
As easy as that -- I checked up.
5.
--SA
Rate this: bad
good
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
 
Enjoy
  Permalink  
Comments
ProgramFOX at 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
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2014
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