Results 1 to 2 of 2

Thread: Change certain text colour in RTFbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    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

  2. #2
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    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.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width