Choose Font

Select a font using the built-in FontDialog component


Public Class Form1

    Private Sub btnChooseFont_Click(sender As Object, e As EventArgs) Handles btnChooseFont.Click
        ' Create and configure the FontDialog
        Dim fontDialog As New FontDialog()
        fontDialog.ShowColor = True
        fontDialog.Font = lblSampleText.Font
        fontDialog.Color = lblSampleText.ForeColor

        ' Show the dialog and get the result
        If fontDialog.ShowDialog() = DialogResult.OK Then
            ' Apply the selected font and color to the label
            lblSampleText.Font = fontDialog.Font
            lblSampleText.ForeColor = fontDialog.Color
        End If
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Set initial text
        lblSampleText.Text = "Sample Text"
        lblSampleText.AutoSize = True
    End Sub

End Class

Download 'Choose Font.vb':

📥 Download choose-font.vb