Results 1 to 2 of 2

Thread: changing text color on 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
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Code:
    Private Sub RichTextBox1_Change()
    
        Static lngStart As Long
        Dim lngFound As Long
        Dim intLen As Integer
        Const LOOK_FOR = "PRIVATE"
        
        intLen = Len(LOOK_FOR)
        
        If lngStart = 0 Then
            lngStart = 1
        End If
        
        lngFound = InStr(lngStart, UCase(RichTextBox1.Text), LOOK_FOR)
        
        If lngFound > 0 Then
            RichTextBox1.SelStart = lngFound - 1
            RichTextBox1.SelLength = lngFound + intLen
            RichTextBox1.SelColor = vbBlue
            RichTextBox1.SelStart = lngFound + intLen + 1
            RichTextBox1.SelColor = vbBlack
            lngStart = lngFound + intLen
        End If
        
    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