Font Dialog Box in VB.net – Properties, Methods and Events

The Font Dialog Box in VB.net lets the user choose the font family, style, and size for the text in an application. A user can also choose the color of the font and apply the current setting to the text of the control that is selected by clicking the Apply button.

We have learned how to use the Color Dialog Boxes in VB.net in the previous lesson. In this lesson we shall learn How To Write a Program for Font Dialog Box in VB.net.

What is Font Dialog in VB.net?

A Font Dialog in VB.net is used to choose a font from a system’s installed fonts. Please keep in mind that a FontDialog may have different fonts on different systems depending on what fonts are installed on a system.

Font Dialog Properties in VB.net

The Font Dialog Box in VB.net has the following Properties:

#Font Dialog Properties in VB.netDescription
1.AllowSimulationsGets or sets a value indicating whether the dialog box allows graphics device interface (GDI) font simulations.
2.AllowVectorFontsGets or sets a value indicating whether the dialog box allows vector font selections.
3.AllowVerticalFontsGets or sets a value indicating whether the dialog box displays both vertical and horizontal fonts, or only horizontal fonts.
4.ColorGets or sets the selected font color.
5.FixedPitchOnlyGets or sets a value indicating whether the dialog box allows only the selection of fixed-pitch fonts.
6.FontGets or sets the selected font.
7.FontMustExistGets or sets a value indicating whether the dialog box specifies an error condition if the user attempts to select a font or style that does not exist.
8.MaxSizeGets or sets the maximum point size a user can select.
9.MinSizeGets or sets the minimum point size a user can select.
10.ScriptsOnlyGets or sets a value indicating whether the dialog box allows selection of fonts for all non-OEM and Symbol character sets, as well as the ANSI character set.
11.ShowApplyGets or sets a value indicating whether the dialog box contains an Applybutton.
12.ShowColorGets or sets a value indicating whether the dialog box displays the color choice.
13.ShowEffectsGets or sets a value indicating whether the dialog box contains controls that allow the user to specify strikethrough, underline, and text color options.
14.ShowHelpGets or sets a value indicating whether the dialog box displays a Help button.
Properties and Descriptions of Font Dialog Box in VB.net

Font Dialog Methods in VB.net

The Font Dialog Box in VB.net has the following Methods:

#Font Dialog Methods in VB.netDescription
1.Equals()The Equals() method is used to check whether the current or defined object is the same.
2.OnHelpRequest()It is used to call the HelpRequest event in the dialog box.
3.Reset()The Reset() method is used to reset all changes to their default values.
4.Dispose()The Dispose() method is used to free all resources used by the Control or the component in the Dialog Box.
5.RunDialog()It is used to override a derived class to create a common dialog box.
6.ShowDialog()The ShowDialog () method is used to run a common dialog box with the default setting.
7.CreateObjRef()The CreateObjRef () method is used to create an object that contains all related information to initialize a proxy that can communicate with a remote object.
Methods and Description of Font Dialog Box in VB.net

Font Dialog Events in VB.net

The Font Dialog Box in VB.net has the following Events:

#Font Dialog Events in VB.netDescription
1.DisposedWhen control or component is terminated by calling the Dispose() method, a Dispose event occurs.
2.HelpRequestWhen a user clicks the Help button of the dialog box, the HelpRequest event is called.
3.ApplyWhen a user clicks on the Apply button of the Font dialog box, an apply event occurs.
Events and Descriptions of Font Dialog Box in VB.net

Let’s make a simple program that uses VB.NET Windows Forms to show the Font dialog box.

Public Class Form1
FontDialog1.ShowColor = True  
        If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then  
            TextBox1.Font = FontDialog1.Font 'Change the font of the selected string  
            TextBox1.ForeColor = FontDialog1.Color 'Change the color of selected string  
        End If  
End Class

Program Output:

Here’s the Output, based on the given program above.

Font Dialog Box in VB.net Output
Font Dialog Box in VB.net Output

Write some text in the TextArea box, as shown below.

Font Dialog Box in VB.net Insert Text
Font Dialog Box in VB.net Insert Text

By choosing the string and clicking the “Change Font” button, the Font window will open. In the Font window, we can change the selected string’s size, font, and font style.

Font Dialog Box in VB.net Change Font
Font Dialog Box in VB.net Change Font

After you set the font, font style, size, color, etc. on the Font dialog box, it shows the formatted string, as shown below.

Font Dialog Box in VB.net Display Results
Font Dialog Box in VB.net Display Results

Summary

A FontDialog Control in VB.net lets the user open the Windows Font Dialog and choose a font and color for the font. In this article, we talked about how to use a Windows Font Dialog in a Windows Forms application using Microsoft Visual Studio and set its properties.


Leave a Comment