26-07-13, 04:26 AM
أريد كود يغير لون الكلمة الي يكتبها مستخدم البرنامج في التكست بوست الى احمر
مثلاً اذا كتب
vb6 تصير الكلمة حمره
واريد الكود مجموعة من الكلمات
مثلاً اذا كتب
vb6 تصير الكلمة حمره
واريد الكود مجموعة من الكلمات
Private Sub Command1_Click()
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 FunctionPrivate 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 FunctionPrivate 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 lOriginalColor As Long
Dim iMatchCount As Integer
lOriginalSelStart = rtb.SelStart
lOriginalSelLength = rtb.SelLength
lOriginalColor = rtb.SelColor
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
rtb.SelColor = lOriginalColor
SetColorWords = iMatchCount
End Function