Link to home
Start Free TrialLog in
Avatar of TommyTwoPints
TommyTwoPintsFlag for Thailand

asked on

Rich box text font

Hi experts

how can i change the font in my rich text box,

The following routines dont work in the way i want.

I want to be able to allow underline, bold and italic at once

Private Sub BBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BBold.Click
        If Me.BBold.ImageIndex = 3 Then
            Me.RTBSendText.Font = New Font(Me.RTBSendText.Font, FontStyle.Bold)
            Me.BBold.ImageIndex = 4
        Else
            Me.RTBSendText.Font = New Font(Me.RTBSendText.Font, FontStyle.Regular)
            Me.BBold.ImageIndex = 3
        End If
    End Sub

    Private Sub BItalic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BItalic.Click
        If Me.BItalic.ImageIndex = 5 Then
            Me.RTBSendText.Font = New Font(Me.RTBSendText.Font, FontStyle.Italic)
            Me.BItalic.ImageIndex = 6
        Else
            Me.RTBSendText.Font = New Font(Me.RTBSendText.Font, FontStyle.Regular)
            Me.BItalic.ImageIndex = 5
        End If
    End Sub

    Private Sub BUnderline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BUnderline.Click
        If Me.BUnderline.ImageIndex = 7 Then
            Me.RTBSendText.Font = New Font(Me.RTBSendText.Font, FontStyle.Underline)
            Me.BUnderline.ImageIndex = 8
        Else
            Me.RTBSendText.Font = New Font(Me.RTBSendText.Font, FontStyle.Regular)
            Me.BUnderline.ImageIndex = 7
        End If
    End Sub

These methods do not preserve the format. If the font was bold before underline is clicked; the boldness is removed and just underline is checked.

Cheers,

Tom
Avatar of newyuppie
newyuppie
Flag of Ecuador image

use Selection Font maybe? try this:

If RTBSendText.SelectionFont.Bold Then
   RTBSendText.SelectionFont = New Font(RTBSendText.SelectionFont, (RTBSendText.SelectionFont.Style And Not               (RTBSendText.SelectionFont.Style And FontStyle.Bold)))
Else
    RTBSendText.SelectionFont = New Font(RTBSendText.SelectionFont, (RTBSendText.SelectionFont.Style Or FontStyle.Bold))
End If

Avatar of TommyTwoPints

ASKER

no, i want to allow bold, italic and underline together.

Cheers.

Tom
Avatar of Mohamed Zedan
for bold as an example do the new font like this.....

Me.RTBSendText.Font = New Font(Me.RTBSendText.Font.FontFamily, Me.RTBSendText.Font.SizeInPoints, Me.RTBSendText.Font.Style Or FontStyle.Bold)

for underline and italic ... change fontstyles.bold to the respective choices...

glad to be of service :)
ASKER CERTIFIED SOLUTION
Avatar of Mohamed Zedan
Mohamed Zedan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Alot:)
you're welcome :)