2016-11-10 55 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

相關問題