40
Visual Basic 6 Black Book:Text Boxes And Rich Text Boxes
RichTextBox1.SelUnderline = True
End Sub
Using Bold, Italic, Underline, And Strikethru
To make text bold, italic, underlined, or strikethru, you use the SelBold, SelItalic, SelUnderline, and
SelStrikethru properties. These properties work on selected RTF text only, so you have to select the text
whose format you want to change.
To make this clearer, here’s an example where we set the underline, bold, italic, and strikethru properties of
text. We start by placing some text into a rich text box:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box supports underlined, bold,_
italic, and strikethru text."
...
Next, we’ll underline the word “underlined” in the text. We start by finding that word using the rich text
box Find() method:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box supports underlined, bold,_
italic, and strikethru text."
RichTextBox1.SelStart = RichTextBox1.Find("underlined")
...
We then use Span() to select the word “underlined”:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box supports underlined, bold,_
italic, and strikethru text."
RichTextBox1.SelStart = RichTextBox1.Find("underlined")
RichTextBox1.Span ("underlined")
...
Finally, we underline the selected text by setting the rich text box’s SelUnderline property to True:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box supports underlined, bold,_
italic, and strikethru text."
RichTextBox1.SelStart = RichTextBox1.Find("underlined")
RichTextBox1.Span ("underlined")
RichTextBox1.SelUnderline = True
...
And we can do the same to demonstrate bold, italic, and strikethru text:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box supports underlined, bold,_
italic, and strikethru text."
file:///E|/Program%20Files/KaZaA/My%20Shared%...Basic%20-%20%20Black%20Book/ch06/209-212.html (2 of 4) [7/31/2001 8:58:21 AM]