Does anyone know how to set the font Italics or bold Properties of the System.Drawing.Font Class?

Here is what I have so far and it works fine but I cannot get the Font Bold or Font Italics to work in the GetSetting Sub?

Thanks for the Help,

TrussworksLeo


#Region "Reg Settings"
Private Sub SaveSettings()

Try
'Place some settings in the registry.
SaveSetting("HBNotePad", "Startup", "Top", "75")
SaveSetting("HBNotePad", "Startup", "Left", "50")

'Font related
SaveSetting("HBNotePad", "Startup", "BackCol", Convert.ToString(textBox1.BackColor.ToArgb()))
SaveSetting("HBNotePad", "Startup", "ForeCol", Convert.ToString(textBox1.ForeColor.ToArgb()))
SaveSetting("HBNotePad", "Startup", "FontName", textBox1.Font.FontFamily.GetName(0))
SaveSetting("HBNotePad", "Startup", "FontSize", Convert.ToString(textBox1.Font.Size))
SaveSetting("HBNotePad", "Startup", "FontBol", Convert.ToBoolean(textBox1.Font.Bold))
SaveSetting("HBNotePad", "Startup", "FontItl", Convert.ToBoolean(textBox1.Font.Italic))

Catch
End Try
End Sub
Private Sub GetSettings()
Try
textBox1.Font = New System.Drawing.Font((GetSetting("HBNotePad", "Startup", "FontName", textBox1.Font.FontFamily.GetName(0))), _
Convert.ToSingle(GetSetting("HBNotePad", "Startup", "FontSize", Convert.ToString(textBox1.Font.Size))))

textBox1.ForeColor = System.Drawing.Color.FromArgb(GetSetting("HBNotePad", "Startup", "ForeCol", Convert.ToString(textBox1.ForeColor.ToArgb())))
textBox1.BackColor = System.Drawing.Color.FromArgb(GetSetting("HBNotePad", "Startup", "BackCol", Convert.ToString(textBox1.BackColor.ToArgb())))

Catch
End Try
End Sub
#End Region

Dani AI

Generated

— the reason the bold/italic flags never show up is that the Font created in your GetSettings code only specifies name and size. FontStyle defaults to Regular unless you explicitly pass a style. Save the bold/italic flags (as "True"/"False") and rebuild a FontStyle value when loading, then use the Font constructor that accepts a style.

Example of constructing the style on load:

' load saved values (use sensible defaults)
Dim fontName As String = GetSetting("HBNotePad","Startup","FontName", SystemFonts.DefaultFont.FontFamily.Name)
Dim fontSize As Single = CSng(GetSetting("HBNotePad","Startup","FontSize", SystemFonts.DefaultFont.Size.ToString()))
Dim isBold As Boolean = False
Boolean.TryParse(GetSetting("HBNotePad","Startup","FontBold","False"), isBold)
Dim isItalic As Boolean = False
Boolean.TryParse(GetSetting("HBNotePad","Startup","FontItalic","False"), isItalic)

Dim style As FontStyle = FontStyle.Regular
If isBold Then style = style Or FontStyle.Bold
If isItalic Then style = style Or FontStyle.Italic

textBox1.Font = New Font(fontName, fontSize, style)

Troubleshooting notes and best practices: use TryParse (shown) so bad registry strings don’t throw exceptions; provide defaults for font name/size; check that the saved font name exists on the machine and fall back to a known family if it doesn’t. For newer VB projects prefer typed settings (My.Settings or ApplicationSettingsBase) rather than SaveSetting/GetSetting for more robust, culture-safe persistence. Also ensure the GetSettings code runs after InitializeComponent so the control exists and isn’t immediately overwritten by other initialization code. ’s post adds no usable guidance.

@@@@@@@@@@@@@@@@@@@

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.