Here you go
VB Code:
Private Sub Command1_Click() Dim lngCount As Long Dim lngLineIndex As Long Dim lngLength As Long Dim lngTotLength As Long Dim strBuffer As String Dim strRichText As String Dim i As Integer Dim intPos As Integer Const WORD_TO_BE_FOUND = "you" 'Get Line count lngCount = SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0) With RichTextBox1 For i = 0 To lngCount - 1 'Get line index lngLineIndex = SendMessage(.hwnd, EM_LINEINDEX, i, 0) 'get line length lngLength = SendMessage(.hwnd, EM_LINELENGTH, lngLineIndex, 0) 'resize buffer strBuffer = Space(lngLength) 'get line text Call SendMessageStr(.hwnd, EM_GETLINE, i, ByVal strBuffer) ' see if the line contains the word intPos = InStr(1, strBuffer, WORD_TO_BE_FOUND) If intPos > 0 Then ' color the line blue .SelStart = lngTotLength .SelLength = lngLength .SelColor = vbBlue ' color the word red .SelStart = intPos + lngTotLength - 1 .SelLength = Len(WORD_TO_BE_FOUND) .SelColor = vbRed End If ' Accumulate the total characters read lngTotLength = lngTotLength + lngLength Next End With End Sub




Reply With Quote