FontDialog Class |
System.Windows.Forms
Yes
Represents a common dialog box for selecting or saving a font.
The FontDialog object has properties for setting the initial appearance and functionality of the dialog box, a property for returning the font selected by the user , as well as a method for showing the dialog box.
The following provides a brief description of the more important members of the FontDialog class:
Sets or retrieves the color of the font. The return value is an instance of the Color structure. The Color structure has a number of members, among which are:
Over 140 named color properties, from Red, Green, and Blue, to PapayaWhip, MistyRose, and MediumSeagreen. These properties return a Color structure.
A Name property, which returns the name of the color or its ARGB value for custom colors. (The A component is the alpha component of the color, which determines the color's opacity.)
The R property, G property, and B property, which return a byte specifying the red, green, or blue color component of the RGB color value, respectively.
The IsKnownColor, IsNamedColor, and IsSystemColor properties, which give information about the color. Please see the documentation for more information on these properties.
Sets or retrieves the font chosen by the user. The return value is an instance of the Font class in the System.Drawing namespace. The Font class has a number of members, among which are:
Boolean properties used to set or retrieve the corresponding attribute of the font.
Returns a FontFamily object associated with the font. Use the Name property to get the name of the font family.
Returns the face name of the font as a String.
Returns the size of the font, in points, as a Single.
Returns a FontStyle constant that contains information about the style of the font. The FontStyle constants are Bold, Italic, Regular, Strikeout, and Underline, and they can be combined using bitwise operations.
These are properties of type Integer that specify the maximum and minimum sizes that can be entered into the Font dialog box.
The FontDialog has properties that specify the features of the dialog box. These include:
Indicates whether the dialog box has an Apply button. (The default is False .)
Indicates whether the dialog box shows the font color choice controls. (The default is False .)
Indicates whether the dialog box shows the strikethrough and underline options. (The default is True .)
The following code displays the Font dialog box and then displays the user's choice of font family:
Imports Microsoft.VisualBasic Imports System Imports System.Windows.Forms Imports System.Drawing Module modMain Public Sub Main Dim fn As New FontDialog( ) fn.ShowEffects = True fn.ShowDialog( ) MsgBox(fn.Font.FontFamily.Name) End Sub End Module
While the FontDialog class is implemented in the .NET Base Class Library, VB 6 offers the CommonDialog custom control. Although the two offer similar functionality, their public interfaces are almost completely different.