FontSyles?

How do you get a multiple fontstyle?
i.e Bold and Italic and Underlined all at the same time.
I have 4 Checkboxes each with a different style, if I click ckbBold
then I get a Bold font in my textbox but if I then click ckbItalic nothing happens until I uncheck ckbBold,
so I only ever get one style.

Any ideas or pointers?

[341 byte] By [Whoisit] at [2007-12-23]
# 1

Does this help?

Me.theTextBox.Font = new Font(Me.theTextBox.Font, FontStyle.Bold OR FontStyle.Underline)

the fontstyle can be combined by using the OR operator

ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Thanks for the reply Admedilyas,
It works but not for the pupose that I need it for see below

Private Sub FontChange()
Dim font_style As FontStyle = FontStyle.Regular

If ckbBold.Checked Then font_style = FontStyle.Bold
If ckbItalic.Checked Then font_style = FontStyle.Italic
If ckbUnderline.Checked Then font_style = FontStyle.Underline
If ckbStrike.Checked Then font_style = FontStyle.Strikeout

' Get the font size.
Dim font_size As Single = 10
Try
font_size = Single.Parse(cmbSize.SelectedItem)
Catch ex As Exception
End Try

' Get the font family name.
Dim family_name As String = "Times New Roman"
If Not (lstbxFonts.SelectedItem Is Nothing) Then
family_name = lstbxFonts.SelectedItem.ToString
End If

' Make the new font.
Dim new_font As New Font(family_name, font_size, font_style)

' Show the Changed font.
txtShow.Font = new_font
End Sub

Whoisit at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

As Ahmedilyas said, you need to OR the font styles, not simply set them:

fStyle = fStyle or FontStyle.Bold

SJWhiteley at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
Ah! now I see

Thanks for that.

Whoisit at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5

How is this Done in C#?

Tim.

TimDev at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6

C#

this.theTextBox.Font = new Font(this.theTextBox.Font, FontStyle.Bold | FontStyle.Underline);

ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...