How to use Font Dialog in VB.Net on runtime

We are very familiar with font dialog, we frequently use font dialog in various  text editor like word pad,MS word,Notepad etc. this is very  important for text managing and editing. net framework provides us strong Font Dialog class, through this we can also change the font size, pattern, style etc of text or selected text.

This article shows how to use fontdialog in application.i have already said that The FontDialog box is pretty familiar to anyone who has used a Windowsbased

word processor. The key point to remember is that its Font property returns

a Font object that you assign to a control or form's Font property.


Example code :  Assumes you have a Richtextbox named RichTextBox1 on your form,

Along with a button that uses the default name of btnFont:

Code :


Private Sub btnFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFont.Click

        Dim FontDlg As New FontDialog

        If FontDlg.ShowDialog = Windows.Forms.DialogResult.OK Then

            If RichTextBox1.SelectedText.Trim = "" Then

                RichTextBox1.Font = FontDlg.Font


                RichTextBox1.SelectionFont = FontDlg.Font

            End If

        End If

    End Sub


Similar Articles