question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RichTextBox `LinkClicked` event doesn't work for "friendly named" hyperlinks

See original GitHub issue
  • .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use dotnet --info)
  • Have you experienced this same bug with .NET Framework?: Yes

Problem description:

With the removal of the quirk Switch.System.Windows.Forms.DoNotLoadLatestRichEditControl (https://github.com/dotnet/winforms/pull/1139/commits/3f2ca8a2a3e19ea7431279defcebec14e2ca59ea) we may regress because we will use newer RTB controls (4.0+) and users will no longer be able to load older RTB controls that handled some hyperlinks differently.

Please refer to https://stackoverflow.com/q/56936777/2338036

Actual behavior:

Expected behavior:

Minimal repro:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
Marie-Shicommented, Sep 10, 2019

Verified this bug with .Net core 3.0.100-rc1-014190 from release branch, RichTextBox LinkClicked event can work for “friendly named” hyperlinks. Please see the following Gif: RichTextBox_LinkClicked

1reaction
weltkantecommented, Aug 20, 2019

@RussKie considering you said in PR #1661 that Issue #1520 will be fixed by said PR, this issue can’t be a duplicate.

This repros on Desktop Framework and I’d assume it also repros in .NET Core. Since the bug fixed by PR #1661 never existed in Desktop Framework it can’t be the same issue. The problem the stackoverflow article was about is a regression in the Desktop Framework long ago (by updating to a newer version of the RTF control which supported features WinForms doesn’t understand).

I’d recommend to reopen so this can be fixed at some point. Of course you are free to reprioritize, it might not be necessary to fix for 3.0 since it repros on Desktop Framework by default and the only thing you took away is the known workaround to downgrade the RTF control.

(Note for anyone wanting to investigate: the exact location of the bug was already root-caused in the stackoverflow article linked in the issue description, so you don’t need to do that yourself again.)

using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

    private RichTextBox richTextBox1;

    public Form1()
    {
        richTextBox1 = new RichTextBox();
        richTextBox1.Dock = DockStyle.Fill;
        richTextBox1.LinkClicked += richTextBox1_LinkClicked;
        ClientSize = new Size(640, 480);
        Controls.Add(richTextBox1);
        Load += Form1_Load;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        richTextBox1.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang4105{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Riched20 10.0.17134}\viewkind4\uc1 
{\field{\*\fldinst { HYPERLINK ""http://www.google.com"" }}{\fldrslt {Click here}}}
\pard\sa200\sl276\slmult1\f0\fs22\lang9  for more information.\par
}";
    }

    private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
    {
        MessageBox.Show($"link {e.LinkText} clicked");
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Some hyperlinks don't trigger the LinkClicked event when ...
When using the Friendly Name Hyperlinks available in the RichEdit50 control, the RichTextBox.Text.Length property can be less than the c.
Read more >
WinForm RichTextBox LinkClicked event fails to fire when ...
RichEdit50 supports showing friendly name hyperlinks, just like the one in this sentence. The LinkClicked event may or may not fire depending on ......
Read more >
RichTextBox doesn't raise LinkClicked for last link.
I load a simple RTF document with several links in it (created with MS Word) into the control. The LinkClicked event does not...
Read more >
Why EventHandler not working for a linklabel in ...
I have done this test to erase the RichTextBox when i click on the generated labellink in the richtextbox. Links are always differents...
Read more >
Links with arbitrary text in a RichTextBox
My extension turns this property off by default because it can interfere with links that have been added programmatically. When the DetectUrls ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found