richtextbox中插入文件路径链接时出错的处理
2008-03-31 09:11
555 查看
本文在http://blog.csdn.net/greystar/archive/2008/03/13/2175958.aspx 此基础上进行了扩展.
当在richtextbox中我们插入一个链接时,如果链接是文件路径时(如C:/aa/bb.doc)时,/符号会丢失.这样如果我们想在些连接上单击时,获取的数据就不正确.
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/ansi " + text + @"/v #" + hyperlink + @"/v0}"; //会出现中文乱码情况, this.SelectedRtf = @"{/rtf1/ansicpg936 " + TextToRtf(text) + @"/v #" + hyperlink + @"/v0}";
this.Select(position, text.Length + hyperlink.Length + 1);
this.SetSelectionLink(true);
this.Select(position + text.Length + hyperlink.Length + 1, 0);
}
//路径处理时用
public string TextToRtf(string AText)
{
string vReturn = "";
foreach (char vChar in AText)
{
switch (vChar)
{
case '//':
vReturn += @"//";
break;
case '{':
vReturn += @"/{";
break;
case '}':
vReturn += @"/}";
break;
default:
if (vChar > (char)127)
vReturn += @"/u" + ((int)vChar).ToString() + "?";
else vReturn += vChar;
break;
}
}
return vReturn;
}
此文上和http://blog.csdn.net/greystar/archive/2008/03/13/2175958.aspx差不多,只是多了一个转换
当在richtextbox中我们插入一个链接时,如果链接是文件路径时(如C:/aa/bb.doc)时,/符号会丢失.这样如果我们想在些连接上单击时,获取的数据就不正确.
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/ansi " + text + @"/v #" + hyperlink + @"/v0}"; //会出现中文乱码情况, this.SelectedRtf = @"{/rtf1/ansicpg936 " + TextToRtf(text) + @"/v #" + hyperlink + @"/v0}";
this.Select(position, text.Length + hyperlink.Length + 1);
this.SetSelectionLink(true);
this.Select(position + text.Length + hyperlink.Length + 1, 0);
}
//路径处理时用
public string TextToRtf(string AText)
{
string vReturn = "";
foreach (char vChar in AText)
{
switch (vChar)
{
case '//':
vReturn += @"//";
break;
case '{':
vReturn += @"/{";
break;
case '}':
vReturn += @"/}";
break;
default:
if (vChar > (char)127)
vReturn += @"/u" + ((int)vChar).ToString() + "?";
else vReturn += vChar;
break;
}
}
return vReturn;
}
此文上和http://blog.csdn.net/greystar/archive/2008/03/13/2175958.aspx差不多,只是多了一个转换
相关文章推荐
- richtextbox中插入文件路径链接时出错的处理
- 加载动态链接库文件.so 失败出错—— No such file or directory (没有文件或目录)问题处理
- Source Insight查看ARM汇编源 && 打开project窗口出错 && 高亮显示程序 && 标题栏显示全路径 && 从工程批量去除文件 && 添加无扩展名文件 && 快捷键插入时间日期
- Java处理文件路径的类
- shell 中带空格的文件路径处理
- ResourceBundle类处理属性文件的路径问题
- 处理 SSI 文件时出错的解决方法
- [Perl][文件操作]判断文件是否为符号链接(Unicode路径)
- 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。
- Java 多文件上传存储到不同的路径及某上传框中未选择上传文件的处理方法
- gcc指定头文件路径及动态链接库路径
- 文件路径相关处理的AP
- mac下bash_profile文件修改后出错处理
- struts2处理上传文件路径问题
- [C/C++]_[初级]_[Windows上的文件路径处理函数]
- 配置节处理程序时出错,未能加载文件或程序集
- 批处理文件快速打开cmd并切到指定路径
- java linux和windows下文件路径间隔符的写法——解决linux下程序在windows下运行时的上传文件出错问题
- 爱普生打印机打印出错,删除打印文件批处理
- .c 文件和 .h 文件的区别 以及 链接出错的问题(四)