user3102153
user3102153

Reputation: 33

richtextbox with greek characters display as?

I am trying to create a custom MessageBox form. I want to display in a richtextbox greek characters but i get ????. The code to call the custom form:

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

The code of the form with the richtextbox

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

d

Upvotes: 1

Views: 340

Answers (2)

user3102153
user3102153

Reputation: 33

I found a solution. I wrote the greek chars in wordpad, saved the file in rtf format and open it with notepad. Doing so i managed to write a replace function for the Greek chars:

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

Upvotes: 2

user7159857
user7159857

Reputation:

Remove the \rtf1\ansi\ and make sure that your editor saves the files in UTF-8 encoding.

Upvotes: 0

Related Questions