Dim t As String
Dim old_pos As Long
Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
RichTextBox1.Find (Chr((KeyAscii))), RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.Span (Chr((KeyAscii)))
RichTextBox1.SelColor = vbBlack
t = t & Chr(KeyAscii)
If KeyAscii = 8 Then old_pos = Len(RichTextBox1.Text) - 1
If KeyAscii = 32 Then
If LCase(Trim(t)) = "html" Then
RichTextBox1.SelStart = 0
RichTextBox1.Find (Trim(t)), old_pos
RichTextBox1.Span (Trim(t))
RichTextBox1.SelColor = vbRed
End If
old_pos = Len(RichTextBox1.Text)
t = ""
End If
RichTextBox1.SelStart = Len(RichTextBox1.Text)
End Sub
这个是简单的例子,当然还有许多问题没处理.如果要判断,肯定得带个数据库,用来存关键字:(