2009-07-21 27 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