Multiple fontstyles for a font

Hi,

Another simple question i'm sure...

I'm trying to create a font with multiple FontStyles... e.g. bold and italic and underlined

I've got the basics for a single fontstyle but just can't work out multiple ones.

Current Code:

Dim fnt as new Font("Times New Roman", 12, FontStyle.Bold)

Any help would be greatly appreciated (can't believe i've been writing apps for the last 5 years and never actually come accross this problem before!!!)

Thanks

[511 byte] By [The_Biochemist] at [2007-12-24]
# 1

OK i've just worked out the 'or' for multiple fontstyles

Dim fnt as new Font("Times New Roman", 12, Fontstyle.Bold OR FontStyle.Italic)

So now i need to change the question a little,

I have checkboxes for bold, italic, Underline, and strikeout each set to false with a single event handler for their checkchanged event calling a function GenerateFont which builds the new font based on the font name, size, and the boolean checked value for each checkbox and returns a font object.

Is there a way of taking new font created on the font name and size and then using it as a prototype to add on the required fontstyles depending on the boolean value of the checkboxes.

e.g.

Private Function GenerateFont(ByVal FontName As String, ByVal Size As Integer, _
ByVal Fontcolor As String, ByVal Bold As Boolean, ByVal Underline As Boolean, _
ByVal Italic As Boolean, ByVal Strikethrough As Boolean) As Font

'Create new prototype font
Dim fnt As Font = New Font(FontName, Size)
'Evaluate each FontStyle and add it to the prototype font if required
If Bold = True Then
fnt = New Font(fnt, FontStyle.Bold)
End If
If Italic = True Then
fnt = New Font(fnt, FontStyle.Italic)
End If
If Underline = True Then
fnt = New Font(fnt, FontStyle.Underline)
End If
If Strikethrough = True Then
fnt = New Font(fnt, FontStyle.Strikeout)
End If
'return the font
Return fnt
End Function

I've tried this (which doesn't work) thinking i could create a prototype font and add the styles on one by one but they just override eachother

I really don't want to have to create nested if statements to take into account every possible combination as that would just be painful!

Thanks again

The_Biochemist at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

OK i've wprked it out, Just me being a bit slow!!!

I've created a Font Generating function that returns a font (below) taking the font name, size, and boolean values for Bold, Italic, Strikeout and Underline.

Private Function GenerateFont(ByVal FontName As String, ByVal Size As Integer, _
ByVal Fontcolor As String, ByVal Bold As Boolean, ByVal Underline As Boolean, _
ByVal Italic As Boolean, ByVal Strikethrough As Boolean) As Font

'Create new prototype font
Dim fnt As Font = New Font(FontName, Size)
'Evaluate the boolean input for each FontStyle and add the fontstyle to the prototype fonts style if required
If Bold = True Then
fnt = New Font(fnt, fnt.Style Or FontStyle.Bold)
End If
If Italic = True Then
fnt = New Font(fnt, fnt.Style Or FontStyle.Italic)
End If
If Underline = True Then
fnt = New Font(fnt, fnt.Style Or FontStyle.Underline)
End If
If Strikethrough = True Then
fnt = New Font(fnt, fnt.Style Or FontStyle.Strikeout)
End If
'return the font
Return fnt
End Function

Works like a charm!

The_Biochemist at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
It's great help, thank you!
ladybird at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...