FontDialog Class

   
FontDialog Class

Namespace

System.Windows.Forms

Createable

Yes

Description

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.

Selected FontDialog Members

The following provides a brief description of the more important members of the FontDialog class:

Color property

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.

Font property

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:

Bold, Italic, Strikout, Underline properties

Boolean properties used to set or retrieve the corresponding attribute of the font.

FontFamily property

Returns a FontFamily object associated with the font. Use the Name property to get the name of the font family.

Name property

Returns the face name of the font as a String.

SizeInPoints

Returns the size of the font, in points, as a Single.

Style

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.

MaxSize, MinSize properties

These are properties of type Integer that specify the maximum and minimum sizes that can be entered into the Font dialog box.

Show... properties

The FontDialog has properties that specify the features of the dialog box. These include:

ShowApply

Indicates whether the dialog box has an Apply button. (The default is False .)

ShowColor

Indicates whether the dialog box shows the font color choice controls. (The default is False .)

ShowEffects

Indicates whether the dialog box shows the strikethrough and underline options. (The default is True .)

Example

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 

VB.NET/VB 6 Differences

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.

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net