handle multiple URL links in a richtextbox

how do you determine which link was clicked

Answer this question

handle multiple URL links in a richtextbox

  • COMGENXP

    Thanks. I don't think that will work because the links will be dynamic and that procedure executes finding the URL when there is no text in the rtb.
  • Matt_

    nevermind, I just realized that LinkText will recognize which link was clicked.
  • Luis Estrada

    yes you would have to setup error checking for the values...ie if the search string is not found it returns negative 1...now if you are saying that you don't know what the urls are in the rtb then you have some serious parsing of the richtext to do to find the potential hyperlinks

  • Teknoshamn

    Private Sub RichTextBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseUp

    Dim TheUrl As String = "www.TheUrl.Com"

    Dim StartIndexOfLink As Integer = Me.RichTextBox1.Find(TheUrl)

    Dim EndIndexOfLink As Integer = StartIndexOfLink + TheUrl.Length

    Dim ClickedIndex As Integer = Me.RichTextBox1.GetCharIndexFromPosition(New Point(e.X, e.Y))

    If ClickedIndex >= StartIndexOfLink AndAlso ClickedIndex <= EndIndexOfLink Then

    MessageBox.Show(TheUrl & " was clicked!")

    End If

    End Sub



  • handle multiple URL links in a richtextbox