Results 1 to 2 of 2

Thread: changing color in the fly

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    Angry

    I have a rich text box that a whole bunch of text gets poured into, I want this text box to check to see if the word "private" is typed in, if it is I want it changed to blue. Any idea how to do this?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Sure thing!
    Code:
    Public Sub ColorWords(pRich As RichTextBox, pWord As String, pColor As OLE_COLOR)
        Dim iPos As Integer
        
        With pRich
            iPos = InStr(iPos + 1, .Text, pWord, vbTextCompare)
            Do While iPos <> 0
                .SelStart = iPos - 1
                .SelLength = Len(pWord)
                .SelColor = pColor
                iPos = InStr(iPos + 1, .Text, pWord, vbTextCompare)
            Loop
        End With
    End Sub
    Now you can call this function like this:
    Code:
    Private Sub Command1_Click()
        ColorWords RichTextBox1, "Private", vbBlue   
    End Sub

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