Link to home
Start Free TrialLog in
Avatar of GarySB
GarySB

asked on

How to read word(s) from RichTextBox only if blue

I have a Richtextbox that uses black and blue font color.  The blue ones are key words that I want the user to be able to click on to display some definition.  How can I read only the words that are blue to the left and/or right of the mouse click to look up my definition?
Avatar of silemone
silemone
Flag of United States of America image

if you convert it to xml, it will have all of the attributes and you can then see the colors of the text...
Avatar of GarySB
GarySB

ASKER

I'm already using a richtextbox for highlighting purpose.  I've seen some other code sample that do something similar, but wrapping might be a issue.  Can the letter/character position of the click be found? and How to test the color of the letter for forcolor blue?
Avatar of GarySB

ASKER

How do you even add a xml? to a Panel or Form?
Avatar of GarySB

ASKER

I prefer a Richtextbox solution
Avatar of Bob Learned
I would think that you could start with the SelectionStart, move the selection back until you find a non-blue character, and then move forward until you get the next non-blue character, or the end of the text.  Then, you would have you range, and you could get the text between those 2 character index markers.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I didn't realize this was a duplicate question...  =\

Anyhoo, at the very bottom of the other question the author states:

    "Can the function be modified to read 'Richtext box' assuming both words are blue.  In other words when the user clicks the mouse on a blue word it should really read all words left and rgiht of the click that are blue."

The approach I posted here is different from the other and actually handles this additional requirement.  The other solution is inspecting the characters looking for word boundaries while my approach is simply looking for where the blue portion starts and stops.

Just thought I'd throw that out there...delete the question if you want.  =)
Avatar of GarySB

ASKER

Thank you for the routine.  As you stated the other solution works for a single word.