I have a RichTextBox, when users type their text, quite often they enter links to some pages. What I want to do is to detect the link and make it a real hyperlink – highlight it, underline it and make it clickable. This should works for two scenarios:
- when user types the link manually (so when a KeyDown event is raised)
- when link is added to the RichTextBox using “paste” functionality
I found the following link: http://forum.phux.org/viewtopic.php?f=18&t=78 but it does not fulfill all the requirements (for instance, the hyperlink is not clickable and the Regex for detecting links has some lacks (e.g. it doesn’t recognize https)
Can someone please help me to find out how to make the hyperlink clickable and how to extend the Regex to fulfill all the requirements?
“(http|https)://([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\’\,]*)?”
its for http/https. You can add ftp, files:/// etc the same way.
to make hyperlink clickable you can do somthing like that:
where MatchedText – is the result of Regex. But not just
Add(), you should to find start and end position of Matched text and perform with it action like above.