BOLD and ITALIC text in RTF Box

lloydsj

Newcomer
Joined
Mar 31, 2003
Messages
14
Hi,

How do I make a buttons for bold, italic, underline etc, that DONT cancel each other out when you use them. ie. If i make my text bold, and then click my italic button it then just turns bold off and makes it italic. Can i make it do both?

Another thing I have thought of, is if i do get it to allow both at the same time.. if I then turn bold off, will it still leave it italic? or will it turn it back to regular?

My code is below!!!

If RTFtext.SelectionFont.Bold = False Then
RTFtext.SelectionFont = New Font("", RTFtext.SelectionFont.Size, FontStyle.Bold)
Else
RTFtext.SelectionFont = New Font("", RTFtext.SelectionFont.Size, FontStyle.Regular)
End If

Cheers,
Stu.
 
Use something like this:

Visual Basic:
' Bold toggle
        If RichTextBox1.SelectionFont.Bold Then
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Xor FontStyle.Bold)
        Else
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Bold)
        End If

' Italic toggle
        If RichTextBox1.SelectionFont.Italic Then
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Xor FontStyle.Italic)
        Else
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Italic)
        End If
 
Back
Top