Links inside rich textbox?

Oztaco - Reinstate Monica C. picture Oztaco - Reinstate Monica C. · Mar 24, 2012 · Viewed 28k times · Source

I know that richtextboxes can detect links (like http://www.yahoo.com) but is there a way for me to add links to it that looks like text but its a link? Like where you can choose the label of the link? For example instead of it appearing as http://www.yahoo.com it appears as Click here to go to yahoo

edit: forgot, im using windows forms

edit: is there something thats better to use (as in easier to format)?

Answer

Mario Fraiß picture Mario Fraiß · Mar 24, 2012

Of course it is possible by invoking some WIN32 functionality into your control, but if you are looking for some standard ways, check this post out: Create hyperlink in TextBox control

There are some discussions about different ways of integration.

greetings

Update 1: The best thing is to follow this method: http://msdn.microsoft.com/en-us/library/f591a55w.aspx

because the RichText box controls provides some functionality to "DetectUrls". Then you can handle the clicked links very easy:

this.richTextBox1.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBox1_LinkClicked);

and you can simple create your own RichTextBox contorl by extending the base class - there you can override the methods you need, for example the DetectUrls.