Click here to Skip to main content
15,796,738 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to be able to add hyperlinks (with placeholder text, not only the link itself being displayed) inside my RichTextBox.

What I have tried:

I tried by adding to the
LinkLabel link = new LinkLabel();
link.Click += link_clicked;
link.Text = text;
link.Tag = value;

but the link is displayed on top of the text and when I save my text to a file I do not have the LinkLabel element there, only the other text I inputed
Updated 5-Aug-23 13:18pm

1 solution

Well, you don't use a LinkLabel. That's only for a label control on a form and has nothing to do with the RichTextBox.

All you do is set the DetectUrl property of the RichTextBox to true and add the URL string in the text as you would any other text.

If you want the user to navigate to those URL's in your own app, make sure you handle the RichTextBox's LinkClicked event so you can open a browser to whatever URL was clicked.

That's it.
Share this answer
AlexandruCrisan 5-Aug-23 18:25pm    
Yes, I could do that, but as I said I want to have a placeholder text for that link. As in microsoft word you do not see the link itself, you see a word/phrase highlighted that you can click on that will open the link eventually
Dave Kreskowiak 5-Aug-23 19:16pm    
Now that gets a lot more complicated. See Links with arbitrary text in a RichTextBox[^] for a wrapper class to make it easier.
AlexandruCrisan 5-Aug-23 19:33pm    
Actually tried that too but when it says that I should get in the LinkClickedEvent the text and link separated by # I only get the text. Maybe too outdated?
Dave Kreskowiak 5-Aug-23 20:28pm    
The RTB in Windows Forms hasn't changed since its creation decades ago.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900