带有希腊字符的 richtextbox 显示为?
richtextbox with greek characters display as?
我正在尝试创建自定义 MessageBox 表单。
我想在 richtextbox 中显示希腊字符,但我得到了 ????。
调用自定义表单的代码:
string msg = "Greek: αβγδ NotGreek:abcd";
using (MsgForm frm = new MsgForm("Caption", msg))
{
frm.ShowDialog();
}
富文本框的表单代码
public MsgForm(string caption, string text)
{
InitializeComponent();
richTextBox1.Rtf = @"{\rtf1\ansi\ " + _text + "}";
}
d
删除 \rtf1\ansi\
并确保您的编辑器以 UTF-8 编码保存文件。
我找到了解决办法。我在写字板中写下了希腊字符,将文件保存为 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");
}
我正在尝试创建自定义 MessageBox 表单。 我想在 richtextbox 中显示希腊字符,但我得到了 ????。 调用自定义表单的代码:
string msg = "Greek: αβγδ NotGreek:abcd";
using (MsgForm frm = new MsgForm("Caption", msg))
{
frm.ShowDialog();
}
富文本框的表单代码
public MsgForm(string caption, string text)
{
InitializeComponent();
richTextBox1.Rtf = @"{\rtf1\ansi\ " + _text + "}";
}
d
删除 \rtf1\ansi\
并确保您的编辑器以 UTF-8 编码保存文件。
我找到了解决办法。我在写字板中写下了希腊字符,将文件保存为 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");
}