Hyperlink Problem

3 posts, 1 answers
  1. Amin
    Amin avatar
    6 posts
    Member since:
    Feb 2012

    Posted 02 Feb 2012 Link to this post

    I have tried you Radrichtextbox with the hyperlink, however, the behaviour of the control is not as expected for the following reasons:

    1- The HyperlinkNavigationMode is set to click - however one still has to CtrlClick

    2- In Private Sub RadRichtextbox_Hyperlinkclicked -- e.handled is set to true - however an external browser is still opened.  I just want to show the URL in a messagebox.

    My project details:
    Form with one radbutton control and one radrichtextbox control

    My code:

    Imports Telerik.WinControls.RichTextBox.FileFormats.Html
    Imports Telerik.WinControls.RichTextBox.Model

    Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Me.RadRichTextBox1.HyperlinkNavigationMode = Telerik.WinControls.RichTextBox.HyperlinkNavigationMode.Click
    Me.RadRichTextBox1.IsReadOnly = True
    End Sub

    Private Sub RadButton1_Click(sender As System.Object, e As System.EventArgs) Handles RadButton1.Click
    Dim provider As New HtmlFormatProvider
    Dim text_for_radrichtextbox As String = ""

    Me.RadRichTextBox1.Document = New RadDocument
    text_for_radrichtextbox = "<p>1. This is the text for the rad richtextbox <a href=" & Chr(34) & "http://www.telerik.com" & Chr(34) & ">Link text to Telerik</a>.</p>"
    Me.RadRichTextBox1.Document = provider.Import(text_for_radrichtextbox
    End Sub

    Private Sub RadRichTextBox1_HyperlinkClicked(sender As Object, e As Telerik.WinControls.RichTextBox.Model.HyperlinkClickedEventArgs) Handles RadRichTextBox1.HyperlinkClicked
    e.Handled = True 'to stop the external browser from opening
    MessageBox.Show(e.URL) 'to show the URL
    End Sub

    End Class

  2. Answer
    Boryana avatar
    330 posts

    Posted 03 Feb 2012 Link to this post

    Hello Amin,

    Thank you for contacting us.

    Please try setting the HyperlinkNavigateMode property to Click and adding an EventHandler for theHyperlinkClicked event after you set the Document property of RadRichTextBox. Here is a sample snippet:
    Private Sub RadButton1_Click(sender As System.Object, e As System.EventArgs) HandlesRadButton1.Click
            Dim provider As New HtmlFormatProvider
            Dim text_for_radrichtextbox As String ""
            Me.RadRichTextBox1.Document = New RadDocument
            text_for_radrichtextbox = "<p>1. This is the text for the radrichtextbox <a href=" & Chr(34) & "http://www.telerik.com" & Chr(34) & ">Link text to Telerik</a>.</p>"
            Me.RadRichTextBox1.Document = provider.Import(text_for_radrichtextbox)
            Me.RadRichTextBox1.HyperlinkNavigationMode = Telerik.WinControls.RichTextBox.HyperlinkNavigationMode.Click
            AddHandler Me.RadRichTextBox1.HyperlinkClicked, AddressOfRadRichTextBox1_HyperlinkClicked
        End Sub

    The reason behind the added lines is that even though HyperlinkNavigateMode and HyperlinkClicked are a property and an event of RadRichTextBox, they are greatly affected by the Document object. In this sense, these are improvements rather than bugs. They are already added to our internal system and we will do our best to implement them in a future release. 

    I hope you find my answer useful. Let me know if I can assist you further.

    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

  3. DevCraft banner
  4. Amin
    Amin avatar
    6 posts
    Member since:
    Feb 2012

    Posted 04 Feb 2012 Link to this post

    The solution presented seems to work - Many thanks.
Back to Top