ARTICLE

Windows Forms FontDialog Component

Posted by Dinesh Beniwal Articles | Visual Basic 2010 September 30, 2009
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
Download Files:
 
Reader Level:

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

Login to add your contents and source code to this article
share this article :
post comment
 

This is correctly.

Posted by Sushta Guthnar Mar 22, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor