Using links in RichTextBox control

  • Thread starter Thread starter Mats-Lennart Hansson
  • Start date Start date
M

Mats-Lennart Hansson

Hi,
I want to dynamically add links into a richtextbox control. However, I
actually don't want to go to a web page, I just want to catch the linkclick
event and do something else.

This works fine by using DetectUrls and writing links like
www.microsoft.com. But how do I do if I don't want the link to look like a
url but like an instruction (e.g Add) instead?

Do I have to use the MouseClick event, then find out on what word the user
clicked and then perform the operation or is there another way? Something
easy like link:Add would be nice if it worked :)

Thanks,

Mats-Lennart
 
You could just set the color of the "links" when you fill the richtextbox:

richTextBox1.Select(startIndex, endIndex);
richTextBox1.SelectionColor = Color.Blue;

And then in your click event for the richTextBox have:

if(richTextBoxRules.SelectionColor == Color.Blue)
....

--Liam.
 
Oh, thats a nice workaround. Annoying I couldn't see it myself though... :)

Thanks!

/Mats-Lennart
 
Back
Top