带有希腊字符的richtextbox显示为?

时间:2018-02-27 13:28:48

标签: c# richtextbox rtf

我正在尝试创建自定义MessageBox表单。 我想在richtextbox中显示希腊字符,但我得到????。 调用自定义表单的代码:

 string msg = "Greek: αβγδ NotGreek:abcd";
                    using (MsgForm frm = new MsgForm("Caption", msg))
                    {
                        frm.ShowDialog();
                    }

包含richtextbox

的表单的代码
public MsgForm(string caption, string text)
        {
            InitializeComponent();
            richTextBox1.Rtf = @"{\rtf1\ansi\ " + _text + "}";
        }

d

2 个答案:

答案 0 :(得分:1)

我找到了解决方案。我在wordpad中写了希腊字符,用rtf格式保存文件并用记事本打开它。这样做我设法为希腊字符写了一个替换函数:

private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = _caption;
            Replace();
            richTextBox1.Rtf = @"{\rtf1\ansi\ansicpg1253 " + _text + "}";
        }

 private void Replace()
        {
            _text = _text.Replace("α", "\\'e1");
            _text = _text.Replace("β", "\\'e2");
            _text = _text.Replace("γ", "\\'e3");
            _text = _text.Replace("δ", "\\'e4");
            _text = _text.Replace("ε", "\\'e5");
            _text = _text.Replace("ζ", "\\'e6");
            _text = _text.Replace("η", "\\'e7");
            _text = _text.Replace("θ", "\\'e8");
            _text = _text.Replace("ι", "\\'e9");
            _text = _text.Replace("κ", "\\'ea");
            _text = _text.Replace("λ", "\\'eb");
            _text = _text.Replace("μ", "\\'ec");
            _text = _text.Replace("ν", "\\'ed");
            _text = _text.Replace("ξ", "\\'ee");
            _text = _text.Replace("ο", "\\'ef");
            _text = _text.Replace("π", "\\'f0");
            _text = _text.Replace("ρ", "\\'f1");
            _text = _text.Replace("ς", "\\'f2");
            _text = _text.Replace("σ", "\\'f3");
            _text = _text.Replace("τ", "\\'f4");
            _text = _text.Replace("υ", "\\'f5");
            _text = _text.Replace("φ", "\\'f6");
            _text = _text.Replace("χ", "\\'f7");
            _text = _text.Replace("ψ", "\\'f8");
            _text = _text.Replace("ω", "\\'f9");

            _text = _text.Replace("Α", "\\'c1");
            _text = _text.Replace("Β", "\\'c2");
            _text = _text.Replace("Γ", "\\'c3");
            _text = _text.Replace("Δ", "\\'c4");
            _text = _text.Replace("Ε", "\\'c5");
            _text = _text.Replace("Ζ", "\\'c6");
            _text = _text.Replace("Η", "\\'c7");
            _text = _text.Replace("Θ", "\\'c8");
            _text = _text.Replace("Ι", "\\'c9");
            _text = _text.Replace("Κ", "\\'ca");
            _text = _text.Replace("Λ", "\\'cb");
            _text = _text.Replace("Μ", "\\'cc");
            _text = _text.Replace("Ν", "\\'cd");
            _text = _text.Replace("Ξ", "\\'ce");
            _text = _text.Replace("Ο", "\\'cf");
            _text = _text.Replace("Π", "\\'d0");
            _text = _text.Replace("Ρ", "\\'d1");
            _text = _text.Replace("Σ", "\\'d3");
            _text = _text.Replace("Τ", "\\'d4");
            _text = _text.Replace("Υ", "\\'d5");
            _text = _text.Replace("Φ", "\\'d6");
            _text = _text.Replace("Χ", "\\'d7");
            _text = _text.Replace("Ψ", "\\'d8");
            _text = _text.Replace("Ω", "\\'d9");

            _text = _text.Replace("ά", "\\'dc");
            _text = _text.Replace("έ", "\\'dd");
            _text = _text.Replace("ή", "\\'de");
            _text = _text.Replace("ί", "\\'df");
            _text = _text.Replace("ό", "\\'fc");
            _text = _text.Replace("ύ", "\\'fd");
            _text = _text.Replace("ώ", "\\'fe");

            _text = _text.Replace("ϋ", "\\'fb");
            _text = _text.Replace("ϊ", "\\'fa");
            _text = _text.Replace("ΰ", "\\'e0");
            _text = _text.Replace("ΐ", "\\'c0");
        }

答案 1 :(得分:0)

删除\rtf1\ansi\并确保编辑器以UTF-8编码保存文件。