TextBox with highlighted words

P

Paul E Collins

I'd like to highlight the current word as the user moves through a
TextBox. I don't mean *select* it, but give it a distinctive
background colour.

The code seems simple enough: whenever the caret moves, search
backwards and forwards in the text to find the next space characters
and highlight what's between them. However, TextBox doesn't support
background colours for partial text, and RichTextBox is unusable
(since you can only set the background colour of the *selected* text,
which is slow, flickery and prone to interfere with the user's own
attempts at making a selection.

Can somebody suggest a good way to do this? A regular TextBox with
OwnerDraw=true seems like a good bet, but the MeasureString-type code
required to work out the region to highlight sounds daunting. Has
anyone made such a (free) class available already?

Eq.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top