Rich Text Box SelectionColor

  • Thread starter Thread starter a_poster
  • Start date Start date
A

a_poster

I'm making a real-time spell checker that mimics MS Word's real-time spell
checking behavior. As the user types into a rich text box, I detect when a
word has been misspelled and modify the visual appearance of the word in
some way (currently I just turn it red).

So, using a rich text box, I have to :

a) bookmark my current .selectionStart into some integer
b) set .selectionStart to the beginning of the misspelled word
c) set .selectionLength to the end of the misspelled word
d) set .selectionColor = [red]
e) set .selectionStart = bookmarked position

I admit this works - the code's fairly efficient and the PC is fast, so I
can accomplish all this faster than anyone can realistically type and the
user has no idea their selection is running wild all over the textbox every
time they leave a word behind. But I had initially envisioned (not knowing
anything about the rich textbox control) a more elegant system of simply
pointing to a substring in the text and changing it's color, or font or
style or whatever, instantly, and without moving the cursor. Was that a
naive dream or is this possible to do without so much modification to the
selection?
 
Your method is the right one (to the best of my knowledge). But you are
right - a more elegant method is necessary. What you say is close to the
way Word does it. It puts properties in property bags and every chunk of
text refers a property bag. So to change the formatting of some text,
you just assign it to some other property bag.

Read Chris Pratley's and Rick Schaut's blog for more details
http://blogs.msdn.com/Chris_Pratley
http://blogs.msdn.com/Rick_Schaut
 
Back
Top