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

Middle-click hyperlinks to open?

2 Answers 91 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 13 Dec 2019, 12:03 AM

Is there a way I can wire up hyperlinks to open when the user clicks on them with the middle mouse button?

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 17 Dec 2019, 09:29 AM

Hi Joshua,

You can use the following approach to achieve this:  

private void RadRichTextBox_MouseDown(object sender, MouseButtonEventArgs e)
{
    if (e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed)
    {
        var position = e.GetPosition(radRichTextBox);
        var sp = this.radRichTextBox.Document.GetLayoutBoxByPosition(this.radRichTextBox.ActiveEditorPresenter.GetDocumentPointFromViewPoint(position).ToPointF()) as SpanLayoutBox;
        var inline = sp.AssociatedInline as Inline;
        var method = typeof(HyperlinkUIProviderBase).GetMethod("OpenHyperlink", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
        method.Invoke(null, new object[] { inline });
    }
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Joshua
Top achievements
Rank 1
answered on 18 Dec 2019, 06:42 AM

Thank you, this gave me exactly what I needed.

Tags
RichTextBox
Asked by
Joshua
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Joshua
Top achievements
Rank 1
Share this question
or