This is a migrated thread and some comments may be shown as answers.

Hyperlink Problem

2 Answers 121 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Amin
Top achievements
Rank 1
Amin asked on 02 Feb 2012, 11:35 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Boryana
Telerik team
answered on 03 Feb 2012, 04:26 PM
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.

Regards,
Boryana
the Telerik team

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

0
Amin
Top achievements
Rank 1
answered on 04 Feb 2012, 10:35 AM
The solution presented seems to work - Many thanks.
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Amin
Top achievements
Rank 1
Answers by
Boryana
Telerik team
Amin
Top achievements
Rank 1
Share this question
or