Change certain text colour in RTFbox
Hey, my brothers not here to help me and im puzzled.
I'm trying to change the text colour of certain words in a rich text box. Say someone types in "[email protected]" I want to change the colour of it but not the rest of the text in the text box.
Any help is great cheers
Re: Change certain text colour in RTFbox
Hi.
This short code will color text in a richtextbox
txtRTB.SelStart = 0
txtRTB.SelLength = Len(txtRTB.Text)
txtRTB.SelColor = vbBlack 'these 3 lines reset the entire box to black,if needed
txtRTB.SelStart = InStr(txtRTB.Text, "the text I want to color") - 1
txtRTB.SelLength = Len("the text I want to color")
txtRTB.SelColor = vbRed 'these 3 lines color the given text red
of course you should do a loop instead of InStr if you need every instance colored.
Next step is to do a check on Text_Change to see if there is a "@" in the text, then parse to find the entire email address and send that to the coloring function
Recoloring the whole box black each time will slow it down, you can omit those 3 lines.
But also, coloring emails blue implies to the user that he can click it and the default email handler will open.