Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change color of text as user types? 1

Status
Not open for further replies.

Kryzsoccer

Programmer
Oct 15, 2002
85
US
I would like to change the color of the text as a user types in a textbox(or similar control) so that certain keywords are different colors. I know that with a Rich Text Box I can change color of text by selecting parts of the text and modifing it. But I have found this does not work well for changing text as a user types.
for example if the user types "the motor" motor should become blue(its a keyword) but if they then add a s("the motors") then motor should go back to being normal.
Maybe my logic to change it needs to be improved or maybe there is a better control to use or better code??

If any of this isnt clear just let me know!
As always all help is appreciated!!
 

No, I think you have the correct control to use so it may be just your code needs a little modification. I think you need to check for white space characters on either side of your keywords before you change their color and/or in your keyword search you need to check to make sure that the keyword is bounded by white space characters and if not make sure it is black.

Good Luck

 
Thanks for the reply!
I have modified my code and things are going better(still not quite there, though).
About finding the white space: i know i could use instr to look for " ". The problem is(sry i didnt mention it before) it doesnt have to be just a whitespace. Is there any way i can use instr to find the next NON-alphanumeric character ("motor." should still color motor). or would I have to go through them myself using mid and IsNumeric and some clever IsAlpha code I have found from this site?
Thanks for your help!
 

Well, I think what you will or could possibly do is something like the psudo code that follows...

if keyword does exist then
get character before and after keyword
if character after does not exist then exit 'user still typing word
if before character and after character = to exception list then
color keyword
else
reset keyword color
end if
end if

Good Luck


 
Thanks for all your help!! Everything works great now!
here is a STAR for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top