Public Sub textcolorchanged()
Dim searchword As String = RichTextBox2.Text.ToString.Trim
Dim index1 As Integer = 0
While index1 <> -1
If (index1 < ORGFILETXT.Text.Length) Then
index1 = ORGFILETXT.Find(searchword, index1, RichTextBoxFinds.None)
'If (index1 <= ORGFILETXT.TextLength) Then
If index1 <> -1 Then
ORGFILETXT.SelectionStart = index1
ORGFILETXT.SelectionLength = searchword.Length
ORGFILETXT.SelectionColor = Color.Red
index1 = index1 + searchword.Length
End If
'End If
Else
index1 = -1
End if
End While
End Sub
I searched word of datagridview1 rows and highlighted search word in rich text-box. text(it is having total text)
I called this method in datagridview1 mouse click and key-up and key down event
word is highlighted in rich text-box.text when I mouse click and key up and key down on datagridview1 rows of search word but some time getting full text is changed color how???
pls help me
Reading the documentation of
RichTextBox.Find Method (String, Int32, RichTextBoxFinds)I have the suspect that, if the string is not found the return value is negative, but not -1.If this is the case then it’s possible that your code fails in setting the selection color.
You could try to change this line
with
See also the their example in MSDN