Search & highlight text in a RichTextBox control

screenshot-thumb1.jpg

A while ago, I needed the ability to search for text in a RichTextBox control and have all occurrences of the query highlighted simultaneously. I thought this was going to be an easy task but soon discovered I was terribly wrong.

Ok, maybe its just me but I wonder why some basic functionalities weren’t just built into these controls from factory by default. Why cant I just call a method such as rtbSample.HighlightInstances(“query”); and have all instances of “query” highlighted?!

Long story short, I modified this example into what I needed and thought to share with everyone. Feel free to also modify it for your projects. And maybe I’ll come up with my custom rich text box control that has this functionality built in someday :). Hmm, before I forget, its in .NET.

Now Playing: The Corrs – Runaway

 
1
Kudos
 
1
Kudos

Now read this

Happy New Year, bitches!

It feels so good to be baaaack! Erm, did I really go anywhere? I know, its January 12 already. Guess a lot of peeps have forgotten they even had a holiday. No, I’ve not. I’m still living it. And hey, did I say I had the best Christmas... Continue →