Private SubRichTextBox1_TextChanged() SubRichTextBox1_TextChanged(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesRichTextBox1.TextChangedDimiAsInteger=RichTextBox1.SelectionStartDimtagetstringAsString=intext.TextDimstrAsString=RichTextBox1.TextDimtoalAsIntegerstr=RichTextBox1.TextRichTextBox1.SelectionStart=0RichTextBox1.SelectionLength=str.LengthRichTextBox1.SelectionColor=Color.BlackFortoal=1Tostr.LengthIfMid(str,toal,1)<>Mid(tagetstring,toal,1)ThenRichTextBox1.SelectionStart=toal-1RichTextBox1.SelectionLength=1RichTextBox1.SelectionColor=Color.RedEndIfNextRichTextBox1.SelectionStart=iRichTextBox1.SelectionLength=0EndSub ’第二版 Dim tagetstring As String = intext.Text Dim str As String = RichTextBox1.Text Dim strsub As Integer = str .Length - strbuff.Lengthrtbsellen = RichTextBox1.SelectionLengthrtbselstart = RichTextBox1.SelectionStartRichTextBox1.SelectionStart = 0 RichTextBox1.SelectionLength = str .LengthRichTextBox1.SelectionColor = Color.Black Dim i As Integer = 0 For i = 1 To str .Length If Mid ( str ,i, 1 ) <> Mid (tagetstring,i, 1 ) Then RichTextBox1.SelectionStart = i - 1 RichTextBox1.SelectionLength = 1 RichTextBox1.SelectionColor = Color.Red End If Next RichTextBox1.SelectionStart = rtbselstartRichTextBox1.SelectionLength = rtbsellenstrbuff = RichTextBox1.Text PublicClassForm1DimstrbuffAsString = "" DimrtbselstartAsIntegerDimrtbsellenAsIntegerPrivateSubRichTextBox1_TextChanged(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesRichTextBox1.TextChangedDimtagetstringAsString = intext.TextDimstrAsString = RichTextBox1.TextDimstrsubAsInteger = str.Length - strbuff.Lengthrtbsellen = RichTextBox1.SelectionLengthrtbselstart = RichTextBox1.SelectionStartRichTextBox1.SelectionStart = 0 RichTextBox1.SelectionLength = str.LengthRichTextBox1.SelectionColor = Color.BlackDimiAsInteger = 0 Fori = 1 Tostr.LengthIfMid(str,i, 1 ) <> Mid(tagetstring,i, 1 )ThenRichTextBox1.SelectionStart = i - 1 RichTextBox1.SelectionLength = 1 RichTextBox1.SelectionColor = Color.RedEndIfNextRichTextBox1.SelectionStart = rtbselstartRichTextBox1.SelectionLength = rtbsellenstrbuff = RichTextBox1.TextEndSubEndClass