图中是两个richtextbox文本框,想要的效果是在下面的文本框中一个一个输入字符,如果与上面的对应字符一样,那么下面的字符变红,下面是代码,高手看看哪里错了,我只能做出最后一个字符变色,十分感谢Private Sub richtextbox1_click()
Dim b As Integer
RichTextBox1.Text = "rice"
For b = 0 To 2 '控制当前插入点
Next
RichTextBox1.SelStart = 0 + b
RichTextBox1.SelLength = 1
If RichTextBox1.SelText = RichTextBox4.SelText Then
b = b + 1
End If
End SubPrivate Sub RichTextBox4_change()
Dim a As Integer
For a = 0 To 3 '控制当前插入点RichTextBox4.SelStart = 0 + a
RichTextBox4.SelLength = 1
If RichTextBox4.SelText = RichTextBox1.SelText Then
RichTextBox4.SelColor = RGB(255, 0, 0)
End If
Next
a = a + 1
End Sub
这是
Dim b As Integer
RichTextBox1.Text = "rice"
For b = 0 To 2 '控制当前插入点
Next
RichTextBox1.SelStart = 0 + b
RichTextBox1.SelLength = 1
If RichTextBox1.SelText = RichTextBox4.SelText Then
b = b + 1
End If
End SubPrivate Sub RichTextBox4_change()
Dim a As Integer
For a = 0 To 3 '控制当前插入点RichTextBox4.SelStart = 0 + a
RichTextBox4.SelLength = 1
If RichTextBox4.SelText = RichTextBox1.SelText Then
RichTextBox4.SelColor = RGB(255, 0, 0)
End If
Next
a = a + 1
End Sub
这是
RichTextBox1.Text = "rice"
RichTextBox4.Text = ""
Timer1.Interval = 100
End Sub
Private Sub RichTextBox4_Change()
I = Len(RichTextBox4.Text)
If I < 1 Then Exit Sub
S1 = Mid(RichTextBox1.Text, I, 1)
S4 = Mid(RichTextBox4.Text, I, 1)
If Not S1 = S4 Then
RichTextBox4.SelStart = I - 1
RichTextBox4.SelLength = 1
RichTextBox4.SelColor = RGB(255, 0, 0)
RichTextBox4.SelColor = RGB(0, 0, 0)
Else
RichTextBox4.SelStart = I - 1
RichTextBox4.SelLength = 1
RichTextBox4.SelColor = RGB(255, 0, 0)
Debug.Print I
End If
RichTextBox4.SelStart = IEnd Sub
Static lngStart As Long
If lngStart = 0 Then lngStart = 1
lngSel = InStr(lngStart, RichTextBox4.Text, RichTextBox1.Text)
lngLen = Len(RichTextBox1.Text)
If lngSel > 0 Then
RichTextBox4.SelStart = lngSel - 1
RichTextBox4.SelLength = lngLen
RichTextBox4.SelColor = RGB(255, 0, 0)
RichTextBox4.SelStart = Len(RichTextBox4.Text)
lngStart = RichTextBox4.SelStart
RichTextBox4.SelColor = vbBlack
End If
End Sub