2009-07-21 45 views
1

我想在vb.net的富文本框中設置一行文本鏈接。例如:我想知道你RichTextBox

這個詞想,我想設置一個鏈接詞。

我可以這樣做嗎?如果可以,請幫助我!

感謝, Sopolin

+0

有這麼多免費的編輯們那裏只是檢查這些 的FCKeditor的一個google一下 – Nagu 2009-07-21 03:53:39

回答

3

這是我會怎麼做。

Dim linkLa As New LinkLabel 
linkLa.LinkColor = Color.Red 

Dim link As LinkLabel.Link = linkLa.Links.Add(0, 13, "http://www.stackoverflow.com") 
linkLa.Text = "Stackoverflow" 
AddHandler linkLa.LinkClicked, AddressOf Link_Clicked 

richTextBox1.Controls.Add(linkLa) 

Private Sub Link_Clicked(ByVal sender As Object, ByVal e As EventArgs) 
    MessageBox.Show("clicked") 
End Sub 
+0

我接受你的答案,但我想顯示的鏈接地址。 – Sopolin 2009-07-21 06:22:36

0

我有一個答案給你。這將允許您顯示鏈接目標地址作爲工具提示。 (幾乎沒有泡沫。)除此之外,它與斯坦R.的答案類似。

  1. 將這個代碼下的「添加鏈接」按鈕(或任何你要調用它)在你的程序

注:我把每行註釋之前,所以它更容易執行!


'define the text and link targets 
Dim linktext As String = LinkTextbox.Text 'LinkTextbox is just the textbox where the user inputs the text of the link 
Dim linktarget As String = LinkTargetTextbox.Text 'LinkTargetTextBox is just the textbox where the user inputs the target URL of the link 

'Define the LinkLabel 
Dim lnk As New LinkLabel 
'if you want, you can set the different properties, like font or linkcolor, programmatically after defining the linklabel, for instance: 
lnk.LinkColor = Color.Blue 
'set tooltip 
lnk.Tooltip = linktarget 
'set the link target 
Dim lk As LinkLabel.Link = lnk.Links.Add(0, 13, linktarget) 
'set the link text 
lnk.Text = linktext 
'EventHandler 
AddHandler lnk.LinkClicked, AddressOf LinkClicked 
'Add the control to the richtextbox 
RichTextBox1.Controls.Add(lnk) 
'This is the Subroutine that the label will run when clicked (Make sure to put your "End Sub" before this, because it's not part of the button's subroutine) 
Private Sub LinkClicked(ByVal sender As Object, ByVal e As EventArgs) 
    'send link to the browser 
    Process.Start(linktarget) 
End Sub