textbox无法实现部分文本的颜色改变,要用RICHTEXTBOX,主要内容我已经写出来了,你看看
Private Sub Command1_Click()
RichTextBox1.SetFocus
End Sub
Private Sub RichTextBox1_Change()
Call duibi
End Sub
Private Sub duibi()
a = Len(Text1.Text)
b = Len(RichTextBox1.Text)
If a > b Then
n = b
Else
n = a
End If
For i = 1 To n
c = Mid(Text1.Text, i, 1)
d = Mid(RichTextBox1.Text, i, 1)
If c = d Then
RichTextBox1.SelStart = i - 1
RichTextBox1.SelLength = 1
RichTextBox1.SelColor = vbBlue
Else
RichTextBox1.SelStart = i - 1
RichTextBox1.SelLength = 1
RichTextBox1.SelColor = vbRed
End If
RichTextBox1.SelStart = i
RichTextBox1.SelColor = vbRed
Next i
RichTextBox1.SelStart = b
RichTextBox1.SelColor = vbRed
End Sub