链接到文件的路径,在RichTextBox的空间? [英] Link to File's path with spaces in RichTextBox?
本文介绍了链接到文件的路径,在RichTextBox的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有VS2010,C#。我用的RichTextBox的形式。我的DectectUrls属性设置为True。我设置了LinkClicked事件
I have VS2010, C#. I use RichTextBox in a form. I set the DectectUrls property to True. I set a LinkClicked event.
我想开一个这样的文件链接:文件:// C:\Documents和设置... 或文件:// C:\Program文件(x86)...
I would like open a file link like this: file://C:\Documents and Settings... or file://C:\Program Files (x86)...
它并不适用于具有空间路径
It doesn't works for path with spaces.
源代码:
rtbLog.SelectionFont = fnormal;
rtbLog.AppendText("\t. Open Path" + "file://" + PathAbsScript + "\n\n");
// DetectUrls set to true
// launch any http:// or mailto: links clicked in the body of the rich text box
private void rtbLog_LinkClicked(object sender, LinkClickedEventArgs e)
{
try
{
System.Diagnostics.Process.Start(e.LinkText);
}
catch (Exception) {}
}
任何建议?
Any suggestions?
推荐答案
最后,我用一个替代(,%20)
Finally, I use a replace (" ", "%20")
// http://social.msdn.microsoft.com/Forums/eu/Vsexpressvb/thread/addc7b0e-e1fd-43f4-b19c-65a5d88f739c
var rutaScript = DatosDeEjecucion.PathAbsScript;
if (rutaScript.Contains(" ")) rutaScript = "file://" + Path.GetDirectoryName(DatosDeEjecucion.PathAbsScript).Replace(" ", "%20");
rtbLog.AppendText(". Abrir ubicación: " + rutaScript + "\n\n");
有关LinkClicked事件中的代码:
The code for LinkClicked event:
private void rtbLog_LinkClicked(object sender, LinkClickedEventArgs e)
{
try
{
var link = e.LinkText.Replace("%20", " ");
System.Diagnostics.Process.Start(link);
}
catch (Exception)
{
}
}
这篇关于链接到文件的路径,在RichTextBox的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文