2016-11-10 57 views
0

我想将文本框字符串转换为超链接,因此当用户点击它时,它将指向该路径。将文本框文本转换为超链接C#windowForm应用程序

string filepath = @"D:\Folder\MyFolder" ; 

我已经厌倦了System.Diagnostics.Process.Start但这将转换整个文本框我想......我想只有特定的字符串。

{ 
    string filepath = @"D:\Folder\MyFolder";  
    textBox3.Text += filepath + "\r\n"; 
    textBox3.Text += "WARNINGS :" + werr + "\r\n\r\n\r"; 
    textFound = true; 
} 
+0

[在c#文本框链接]的可能的复制(http://stackoverflow.com/questions/321037/links-in-c-sharp-textbox) – active92

回答

0

我认为使用RichtextBox将是一个好主意。

1)设置DetectUrls属性为true ,然后就转到{} YourFormName了.Designer.cs 写你的事件处理程序现在低于所有其他RichTextBox的处理程序写这

,然后按TAB两次。它会为你创建这个事件处理程序。

private void mRichTextBox_LinkClicked (object sender, LinkClickedEventArgs) 
{  
    // Add this line inside this Event Handler. 
    System.Diagnostics.Process.Start(e.LinkText); 

    //This will only open Click Link in Default browser. Links will automatically get underlined as for hyperlinks. 
} 

2)(可选)将Multiline属性设置为false。这将使它看起来像普通的文本框。

I found the answer here

+0

但这里需要多行文本框,并我希望链接中的微粒字符串不是整个文本框。 –

+0

是的,它会做到这一点 – Charlie

相关问题