我有一个富文本框,我想在上面使用超链接,所以当用户点击它时,网站链接或本地文件被打开。在我上一个问题中,我说链接点击事件没有正常触发,这个问题解决了,但现在我有另一个问题。
我尝试创建一个超链接,我的字符是 utf8(波斯语/阿拉伯语)。但是例如当我写这篇文章时
并选择“cast”作为链接文本,“C:\Users\sadegh\Desktop .txt”作为 url,结果是:سلام 带?
سلام 带?? file://C:/Users/sadegh/Desktop/16.txtخبر؟我该如何解决这个问题?我的代码是:
private void AddLinkBtn_Click(object sender, EventArgs e)
{
string url = null;
OpenFileDialog openFileDialog = new OpenFileDialog();
//openFileDialog.Filter = "Image Files (*.jpg;*.jpeg,*.png)|*.JPG;*.JPEG;*.PNG";
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
url = openFileDialog.FileName;
}
if (!string.IsNullOrEmpty(url))
{
string linkText = TextBoxDefinition.SelectedText;
byte[] bytes = Encoding.UTF8.GetBytes(linkText);
linkText = Encoding.UTF8.GetString(bytes);
TextBoxDefinition.SelectedRtf = @"{\rtf1\utf8\field{\*\fldinst HYPERLINK ""file://" + url.Replace("\\", "/") + @""" }{\fldrslt" + linkText + "}}";
}
}
更新:我忘记说了。我使用 .NET Framework 4.5.