I'm writing a simple text editor, I have a combobox to select a given font, the problem is that if the font doesn't support Regular then the program crashes.
How do I get around this? below is the code
How do I get around this? below is the code
VB.NET:
Private Sub Style()
If Not rtbText.SelectionFont Is Nothing Then
Dim currentFont As System.Drawing.Font = rtbText.SelectionFont
Dim newFontStyle As System.Drawing.FontStyle
If Bold = True Then newFontStyle = newFontStyle Or FontStyle.Bold
If Italic = True Then newFontStyle = newFontStyle Or FontStyle.Italic
If Strike = True Then newFontStyle = newFontStyle Or FontStyle.Strikeout
If Under = True Then newFontStyle = newFontStyle Or FontStyle.Underline
' Get the font size.
Dim font_size As Single = 10
Try
font_size = Single.Parse(cboSize.SelectedItem)
Catch ex As Exception
End Try
rtbText.SelectionFont = New Font(currentFont.FontFamily, font_size, newFontStyle)
End If
End Sub