Avatar of cmerlo1
 asked on

C# Insert Clickable Link into RichTextBox

    I am working on a knowledgebase application.  I'm storing images and attachments to the articles in a separate table in the database.  I would like to be able to allow the author of an article to be able to insert a clickable link into the article, which is entered and displayed in a rich text box.  When a user clicks the link, the image is retrieved from the database and is displayed.
     I've tried using the 'RichTextLinks' dll from CodeProject (http://www.codeproject.com/KB/edit/RichTextBoxLinks.aspx), but the links it inserts can't be saved.
     Is there a way to create a saveable, clickable link in a rich text box, that fires the LinkClicked event?

Avatar of undefined
Last Comment

8/22/2022 - Mon

Would it not suffice to use a regular RichTextBox with DetectUrls set to true?


You can handle the LinkClicked event of the RichTextBox to actually do something when the link is clicked. For example, to open up IE at the link:
private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
    System.Diagnostics.Process.Start("iexplore", e.LinkText);

Open in new window


Correct, but how can I insert a link that isn't a URL?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

but how can I insert a link that isn't a URL?
Are you referring to a relative path?

This is a sentence with a link to a myfolder/pics/img1.png file in it.

Open in new window


No, I'm going to pull an image from the database when the link is clicked and display it.  I'm not really linking to anything, I just want something clickable, that has the identity of the image I'm going to display.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

The issue was that the Code Project links weren't saveable.  I figured out how to save what they were, and repopulate them.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.