链接到 Richtextbox 中带空格的文件路径 [英] Link to file path with space in Richtextbox

查看:27
本文介绍了链接到 Richtextbox 中带空格的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 winforms 中使用富文本框.我必须在 Richtextbox 中显示一些链接,这些链接将被设置为只读.它适用于像

I am using richtextbox in winforms. I have to show some links in the richtextbox which will be set readonly. It works fine for the links with out spaces like

\\efile\DSC_0618.JPG

\\efile\DSC_0618.JPG

但是当文件有像

\\2527 threshold.png

\\2527 threshold.png

它不会工作,链接会因空间而损坏.

it wont work and link will get broke due to space.

我使用了此链接中提到的解决方案 链接到文件的路径RichTextBox 中有空格吗?

i have used the solution mentioned in this link Link to File's path with spaces in RichTextBox?

但问题是转义序列也会根据此显示在 Richtextbox 中.

But the problem is that escape sequence also get displayed in the Richtextbox according to that.

有什么办法可以在不使用转义序列的情况下将其设为链接吗?

Is there any way i can make it as link without using escape sequence?

推荐答案

我找到了这个链接 http://www.codeproject.com/cs/miscctrl/RichTextBoxLinks.asp 它可以帮助您将任何文本的链接插入 RichTextBox.这里有一个关于如何获取 LinkTextLink Url 的特别说明,在原始演示中似乎没有找到.这里我将演示在 LinkClicked 事件处理程序中获取链接信息:

I've found this link http://www.codeproject.com/cs/miscctrl/RichTextBoxLinks.asp which can help you insert a link of any text into a RichTextBox. There is a special note about how to fetch the LinkText and Link Url here which doesn't seem to be found in the original demo. Here I'll demonstrate the link info fetching in LinkClicked event handler:

//Insert link to test
richTextBoxEx1.InsertLink("StackOverFlow", "http://www.stackoverflow.com");
//LickClicked event handler
private void richTextBoxEx1_LinkClicked(object sender, System.Windows.Forms.LinkClickedEventArgs e)
{
        string[] s = e.LinkText.Split(new string[]{@"#http://"}, StringSplitOptions.None);
        if (s.Length == 2)
        {
            s[1] = "http://" + s[1];
            MessageBox.Show("A link has been clicked.\nThe link text is '" + s[0] + "'\nThe link URL is '" + s[1] + "'");
            System.Diagnostics.Process.Start(s[1]);//Try visiting the link.
        }
}

我认为这对您(以及其他遇到相同问题的人)来说是最漂亮的解决方案.

I think this is the most beautiful solution for you (and others who have the same problem).

这篇关于链接到 Richtextbox 中带空格的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆