|
-
Apr 19th, 2004, 01:54 PM
#1
Thread Starter
New Member
Search & Highlight terms in a RTF Box
Hi,
I’m fairly new at VB.Net and I’m having a few problems highlighting text in a Rich Text Box. I am working on a text editor that will have some text in the RTF Box and a regular text box where the user can enter a search term. When the find button is clicked, the first occurrence of the search term in the RTF box is highlighted if it exists in the Rich TextBox. If find is clicked again, the highlight moves to the next occurrence of the search term and so on.
What I have done so far (not sure if this is the best way) is to put the contents of the RTF box into a string variable, search the string with the RTF contents for the find term, highlight the term, and then remove the first occurrence of the search term and everything before it from the string. Problem is, the RTF textbox displayed will need to keep all of the text, so when I search again, the highlighting messes up.
Can someone help me with this?
-
Apr 19th, 2004, 02:33 PM
#2
Frenzied Member
look at SelectedText propery of RTF
VB Code:
Private Sub WriteTextToRichTextBox()
' Clear all text from the RichTextBox;
richTextBox1.Clear()
' Set the font for the opening text to a larger Arial font;
richTextBox1.SelectionFont = New Font("Arial", 16)
' Assign the introduction text to the RichTextBox control.
RichTextBox1.SelectedText = "The following is a list of bulleted items:" + ControlChars.Cr
' Set the Font for the first item to a smaller size Arial font.
richTextBox1.SelectionFont = New Font("Arial", 12)
' Specify that the following items are to be added to a bulleted list.
richTextBox1.SelectionBullet = True
' Set the color of the item text.
richTextBox1.SelectionColor = Color.Red
' Assign the text to the bulleted item.
richTextBox1.SelectedText = "Apples" + ControlChars.Cr
' Apply same font since font settings do not carry to next line.
richTextBox1.SelectionFont = New Font("Arial", 12)
richTextBox1.SelectionColor = Color.Orange
richTextBox1.SelectedText = "Oranges" + ControlChars.Cr
richTextBox1.SelectionFont = New Font("Arial", 12)
richTextBox1.SelectionColor = Color.Purple
richTextBox1.SelectedText = "Grapes" + ControlChars.Cr
' End the bulleted list.
richTextBox1.SelectionBullet = False
' Specify the font size and string for text displayed below bulleted list.
richTextBox1.SelectionFont = New Font("Arial", 16)
richTextBox1.SelectedText = "Bulleted Text Complete!"
End Sub
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
|