TextBox with highlighted words

  • Thread starter Thread starter Paul E Collins
  • Start date Start date
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.
 
Back
Top