|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Setting Fonts And Font Sizes In Rich Text BoxesAnother call from the Field Testing Department. It seems that the users want to use different fonts in your word-processor program. Well, some people are never satisfiedbut rich text boxes can help here, too. To set a selections font, you just set the SelFontName to the new font name (for example, Arial or Times New Roman). To set a selections font size, you just set the SelFontSize property. Thats all it takes. Heres an example. In this case, well display the text This rich text box supports fonts like Arial and Courier in different sizes. in a rich text box, and format the words Arial and Courier in those fonts, and in different font sizes. We start by placing that text in a rich text box:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box supports fonts like Arial and_
Courier in different sizes."
...
Next, we select the word Arial:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box supports fonts like Arial and_
Courier in different sizes."
RichTextBox1.SelStart = RichTextBox1.Find("Arial")
RichTextBox1.Span ("Arial")
...
Then we display that word in Arial font, with a 24-point size:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box supports fonts like Arial and_
Courier in different sizes."
RichTextBox1.SelStart = RichTextBox1.Find("Arial")
RichTextBox1.Span ("Arial")
RichTextBox1.SelFontName = "Arial"
RichTextBox1.SelFontSize = 24
...
We do the same for the word Courier, displaying it in 18-point size:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box supports fonts like Arial and_
Courier in different sizes."
RichTextBox1.SelStart = RichTextBox1.Find("Arial")
RichTextBox1.Span ("Arial")
RichTextBox1.SelFontName = "Arial"
RichTextBox1.SelFontSize = 24
RichTextBox1.SelStart = 0
RichTextBox1.SelStart = RichTextBox1.Find("Courier")
RichTextBox1.Span ("Courier")
RichTextBox1.SelFontName = "Courier"
RichTextBox1.SelFontSize = 18
End Sub
The result appears in Figure 6.11.
Being able to set the font and font size of individual text selections instead of working with all the text at once in a rich text box is a very powerful capability. Using Bullets In Rich Text BoxesRich text boxes support bullets, those black dots that appear in lists of items that you want to set off in text. Putting a bullet in front of each item gives the list a snappy appearance and helps the reader assimilate the information quickly. To set bullets, you use the SelBullet and BulletIndent properties. The SelBullet property displays a bullet in front of the paragraph in which the current selection is; the BulletIndent property indicates how much you want the bullet to be indented from the left.
Lets make this clearer with an example. We start by placing some text in a rich text box:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box shows how to use bullets _
and indent bulleted text."
...
We set the indentation for this paragraph to 200 twips:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box shows how to use bullets _
and indent bulleted text."
RichTextBox1.SelIndent = 200
...
Next, we set the bullets indent to 90 twips, so its set off from the rest of the text. We set that indent with the BulletIndent property:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box shows how to use bullets _
and indent bulleted text."
RichTextBox1.SelIndent = 200
RichTextBox1.BulletIndent = 90
...
Finally, we add the bullet with the SelBullet property:
Private Sub Command1_Click()
RichTextBox1.Text = "This rich text box shows how to use bullets _
and indent bulleted text."
RichTextBox1.SelIndent = 200
RichTextBox1.BulletIndent = 90
RichTextBox1.SelBullet = True
End Sub
Thats itthe result appears in Figure 6.12.
Aligning Text In A Rich Text BoxYou can set the alignment of text in a rich text box paragraph-by-paragraph using the SelAlignment property. You just select the paragraph you want to align, or place the insertion point in that paragraph, and set the SelAlignment property to one of the following values:
Being able to align text paragraph-by-paragraph like this is much more powerful than the simple Alignment property of a standard text box, which aligns all the text at the same time.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |