日期:2014-05-18  浏览次数:20920 次

winform 后台通过rtf实现richtextbox自定义文本超链接
winform 后台通过rtf实现richtextbox自定义文本超链接
/// <param name="text">自定义文本</param> 
/// <param name="hyperlink">目标地址(可是URL地址,或者是文件路径)</param>
/// <param name="position">Insert position</param>
 public void InsertLink(string text, string hyperlink, int position)
  {
  if (position < 0 || position > this.Text.Length)
  throw new ArgumentOutOfRangeException("position");

  this.SelectionStart = position;
  this.SelectedRtf = @"{\rtf1\ansicpg936\" + text + @"\v #" +hyperlink + @"\v0}";
  this.Select(position, text.Length + hyperlink.Length + 1);
  this.SetSelectionLink(true);
  this.Select(position + text.Length + hyperlink.Length + 1, 0);
  }

前台:private void commRichTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
  {
  string uri = e.LinkText.Substring(e.LinkText.IndexOf('#') + 1, e.LinkText.Length - e.LinkText.IndexOf('#') - 1);

现在情况是:1:当文件路径中包含英文 英文被抹杀掉
  2:文件路径“\”全部丢失掉


麻烦各位给点建议 感谢

------解决方案--------------------
替换一下就可以了啊