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.net | Description |
---|---|---|
1. | AllowSimulations | Gets or sets a value indicating whether the dialog box allows graphics device interface (GDI) font simulations. |
2. | AllowVectorFonts | Gets or sets a value indicating whether the dialog box allows vector font selections. |
3. | AllowVerticalFonts | Gets or sets a value indicating whether the dialog box displays both vertical and horizontal fonts, or only horizontal fonts. |
4. | Color | Gets or sets the selected font color. |
5. | FixedPitchOnly | Gets or sets a value indicating whether the dialog box allows only the selection of fixed-pitch fonts. |
6. | Font | Gets or sets the selected font. |
7. | FontMustExist | Gets 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. | MaxSize | Gets or sets the maximum point size a user can select. |
9. | MinSize | Gets or sets the minimum point size a user can select. |
10. | ScriptsOnly | Gets 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. | ShowApply | Gets or sets a value indicating whether the dialog box contains an Applybutton. |
12. | ShowColor | Gets or sets a value indicating whether the dialog box displays the color choice. |
13. | ShowEffects | Gets or sets a value indicating whether the dialog box contains controls that allow the user to specify strikethrough, underline, and text color options. |
14. | ShowHelp | Gets or sets a value indicating whether the dialog box displays a Help button. |
Font Dialog Methods in VB.net
The Font Dialog Box in VB.net has the following Methods:
# | Font Dialog Methods in VB.net | Description |
---|---|---|
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. |
Font Dialog Events in VB.net
The Font Dialog Box in VB.net has the following Events:
# | Font Dialog Events in VB.net | Description |
---|---|---|
1. | Disposed | When control or component is terminated by calling the Dispose() method, a Dispose event occurs. |
2. | HelpRequest | When a user clicks the Help button of the dialog box, the HelpRequest event is called. |
3. | Apply | When a user clicks on the Apply button of the Font dialog box, an apply event occurs. |
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.
Write some text in the TextArea box, as shown below.
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.
After you set the font, font style, size, color, etc. on the Font dialog box, it shows the formatted string, as shown below.
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.
PREVIOUS
NEXT