26-07-13, 05:44 AM
أخي لازم تستخدم أداة ال RichTextBox ، ثم أنسخ هذا الكود وإلصقه في داخل كود الفورم :
- جرب .
كود :
Private Sub RichTextBox1_Change()
SetColorWords RichTextBox1, "vb6", vbRed
End Sub
Private Function SetColorWords(rtb As RichTextBox, _
sFindString As String, _
lColor As Long) _
As Integer
Dim lFoundPos As Long
Dim lFindLength As Long
Dim lOriginalSelStart As Long
Dim lOriginalSelLength As Long
Dim iMatchCount As Integer
lOriginalSelStart = rtb.SelStart
lOriginalSelLength = rtb.SelLength
lFindLength = Len(sFindString)
lFoundPos = rtb.Find(sFindString, 0, , rtfNoHighlight)
While lFoundPos > 0
iMatchCount = iMatchCount + 1
rtb.SelStart = lFoundPos
rtb.SelLength = lFindLength
rtb.SelColor = lColor
lFoundPos = rtb.Find(sFindString, _
lFoundPos + lFindLength, , rtfNoHighlight)
Wend
rtb.SelStart = lOriginalSelStart
rtb.SelLength = lOriginalSelLength
SetColorWords = iMatchCount
End Function- جرب .

