Windows Forms FontDialog Component in VB.NET

The Windows Forms FontDialog component is a pre-configured dialog box, which is the standard Windows "Font" dialog box used to expose the fonts that are currently installed on the system
  • 2451
Download Files:
 
Introduction
 
The Windows Forms FontDialog component is a pre-configured dialog box, which is the standard Windows "Font" dialog box used to expose the fonts that are currently installed on the system. Use it within your Windows application as a simple solution for font selection in lieu of configuring your own dialog box.

By default, the dialog box shows list boxes for Font, Font style, and Size; check boxes for effects like Strikeout and Underline; a drop-down list for Script; and a sample of how the font will appear. (Script refers to different character scripts that are available for a given font, for example Hebrew or Japanese.) To display the font dialog box, call the ShowDialog method.

The component has a number of properties that configure its appearance. The properties that set the dialog-box selections are Font and Color. The Font property sets the font, style, size, script, and effects; for example, Arial, 10pt, style=Italic, Strikeout.

Showing a Font List with the FontDialog Component
 
The FontDialog component allows users to select a font, as well as change its display aspects, such as its weight and size.

The font selected in the dialog box is returned in the Font property. Thus, taking advantage of the font selected by the user is as easy as reading a property.

To select font properties using the FontDialog Component

  1. Display the dialog box using the ShowDialog method.
  2. Use the DialogResult property to determine how the dialog box was closed.
  3. Use the Font property to set the desired font.

    In the example below, the Button control's Click event handler opens a FontDialog component. When a font is chosen and the user clicks OK, the Font property of a TextBox control that is on the form is set to the chosen font. The example assumes your form has a Button control, a TextBox control, and a FontDialog component.

    Private Sub Button1_Click(ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles Button1.Click
       If FontDialog1.ShowDialog() = DialogResult.OK Then
          TextBox1.Font = FontDialog1.Font
       End If
    End Sub

    When you will click on the button1 the screen will come :

    font1.gif

    Figure 1

    font2.gif

    Figure 2

    After selecting the Font Size the Result will be :

    font3.gif

    Figure 3

    Source Code
    Source code attach in the top of the article

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.