Search In Site

27 June, 2013

Using Fonts And Bullets in rich text boxes in Visual Basic

Setting Fonts And Font Sizes In Rich Text Boxes
Another 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 satisfied but rich text boxes can help here, too. 
To set a selection's 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. That's all it takes.Here's an example. In this case, we'll 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

Using Bullets In Rich Text Boxes
Rich 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. 

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 bullet_s indent to 90 twips, so it_s 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

0 comments:

Post a Comment

Dear Visitors All The Tricks And Hacks Posted Here Are Only For Knowledge Purpose.Don't Use These for Illegal Operations.

 
Twitter Bird Gadget