本文介绍了在RichTextBox(Verdana)中显示Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



最近,当使用的字体为Verdana时,RichTextBox显示Unicode字符(尤其是阿拉伯语)时出现了一些问题.
但是,在Label或TextBox上显示相同的内容将显示良好和正确的结果.同样,当使用Microsoft Sans Serif代替Verdana时.

有谁知道如何解决吗?您可以将以下内容作为任一控件的Text属性的示例输入:

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)
ﺃ, ﺐ, ﺕ, ﺚ, ﺝ, ﺡ, ﺥ, ﺪ, ﺫ, ﺭ, ﺯ, ﺱ, ﺵ, ﺹ , ﺽ, ﻁ , ﻅ, ﻉ, ﻍ, ﻑ, ﻕ, ﻙ, ﻝ, ﻡ, ﻥ, ﻩ, ﻭ, ﻱ



在使用Verdana的RichTextBox上,阿拉伯字符将显示为正方形.您也可以尝试以下代码:



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();
        }
    }
}



最好的问候,
Michael



Best regards,
Michael

推荐答案


RichTextBox1.Text = (System.Text.RegularExpressions.Regex.Replace(str, "(\d{3,}?);", New System.Text.RegularExpressions.MatchEvaluator(AddressOf ConvertCode)))



只需通过此站点将其转换为C或C#

转换代码站点

享受



Just Convert this in C or C# by this site

Convert Code Site

Enjoy


这篇关于在RichTextBox(Verdana)中显示Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:39