C# Insert Clickable Link into RichTextBox

cmerlo1
cmerlo1 used Ask the Experts™
on
    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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Would it not suffice to use a regular RichTextBox with DetectUrls set to true?
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
P.S.

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

Author

Commented:
Correct, but how can I insert a link that isn't a URL?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

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

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

Open in new window

Author

Commented:
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.
Commented:
Thank for your help- I figured it out.  I used the RichTextBoxLinks .dll from the Code Project site, and stored the link text and target in a table in the database.  When the article loads, the link text is replaced with the link.  Works great!

Author

Commented:
The issue was that the Code Project links weren't saveable.  I figured out how to save what they were, and repopulate them.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial