Reputation: 2852
Im trying to make the following thing :
1) using regex to match all strings that have the following pattern "@username" << done i got the pattern @([A-z09_-]){4,20}
2) to parse the text from rich text box and to color those patterns "@somethign" in a color
3) make them clickable & when clicked to insert the clicked string in text box ( only if this is possible without tons of code & libraries )
well . thats basically it .. any help is appreciated :) ' Cheers :)
Upvotes: 0
Views: 1674
Reputation: 23921
Use regexp to find all occurances of "@username", and store them in a collection. Then iterate through this collection and do this:
int startpos = 0;
if ( ( startpos = richTextBox1.Find(name) ) > 0 )
{
richTextBox1.SelectionStart = startpos;
richTextBox1.SelectionLength = name.Length;
richTextBox1.SetSelectionLink(true);
}
Note that this uses an extended richtextbox found here: Link. (The SetSelectionLink is not in the vanilla richtextbox class.)
Upvotes: 2