Creating custom font dialog box in VB.NET

This article shows how to create a font dialog box in VB.NET windows forms application.
  • 3996

In this article we will learn about the font dialog control in window application in VB.NET.

Font Dialog

Font dialog control are used to select a color and Font. Font dialog control has some common property which are as following:

Color

Color Property used to get or set the selected font color.

Font

Font Property used to get or set the selected font.

ShowColor

Showcolor Property used to set or get whether the dialog box display the color choice.
 

ShowDialog method

To display the dialog box to the user, call the ShowDialog() method. 

For example:

click the FontDialog button from toolbox it will take place below the form and take two control text box and button to the form .

font.gif

font2.gif  

Now, double click on the button named color in the form and write the following code.

Private Sub cmdFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFont.Click

        FontDialog1.ShowColor = True

        FontDialog1.ShowDialog()

        textBox4.Font = FontDialog1.Font

        textBox4.ForeColor = FontDialog1.Color

    End Sub


 

Now press Ctrl+F5 to run the application.

The below window will appear and we write some text on the text box and than and then click on the button named color.

 

font5.gif
 

Now select the color and font  from the color box and click on the button OK and color and font will display on the textbox.

 

We choose color red and font size 12 from the color box and click on the button OK. textbox text will display as shown below.

font6.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.