|
-
Oct 6th, 2005, 08:21 AM
#1
RichTextBox - Highlight / Bold all occurances of a word
VB Code:
Private Sub ColorWord(prtbName As RichTextBox, _
pstrWord As String, _
plngHighlightColor As Long, _
Optional pblnBold As Boolean)
Dim lngPos As Long
Dim lngSelStart As Long
Dim lngSelLength As Long
lngSelStart = prtbName.SelStart
lngSelLength = prtbName.SelLength
lngPos = prtbName.Find(pstrWord, 0)
Do
prtbName.SelColor = plngHighlightColor
If pblnBold = True Then
prtbName.SelBold = True
End If
lngPos = prtbName.Find(pstrWord, lngPos + prtbName.SelLength)
Loop While lngPos > 0
prtbName.SelStart = lngSelStart
prtbName.SelLength = lngSelLength
End Sub
usage
ColorWord RichTextBoxControl , "Word to Find", color ,[Optional BOLD as Boolean]
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Oct 6th, 2005, 09:34 AM
#2
Re: RichTextBox - Highlight / Bold all occurances of a word
For a bit more flexibility when using the routine, add a checkbox to the form (call it chkBold) and a CommonDialog control. Then, use this to call the word coloring.
VB Code:
Private Sub Command1_Click()
CommonDialog1.ShowColor
If chkBold.Value = vbChecked Then
ColorWord RichTextBox1, Text1.Text, CommonDialog1.Color, True
Else
ColorWord RichTextBox1, Text1.Text, CommonDialog1.Color
End If
End Sub
This permits you to choose the color you wish to use when highlighting the word and to decide whether or not you want the word to be bolded after highlighting or not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|