Export (0) Print
Expand All
4 out of 5 rated this helpful - Rate this topic

FontDialog Class

Represents a common dialog box that displays a list of fonts that are currently installed on the system.

For a list of all members of this type, see FontDialog Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.CommonDialog
            System.Windows.Forms.FontDialog

[Visual Basic]
Public Class FontDialog
   Inherits CommonDialog
[C#]
public class FontDialog : CommonDialog
[C++]
public __gc class FontDialog : public CommonDialog
[JScript]
public class FontDialog extends CommonDialog

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The inherited member ShowDialog must be invoked to create this specific common dialog box. HookProc can be overridden to implement specific dialog box hook functionality.

When you create an instance of FontDialog, some of the read/write properties are set to initial values. For a list of these values, see the FontDialog constructor.

Example

[Visual Basic, C#, C++] The following example uses ShowDialog to display a FontDialog. This code assumes that a Form has already been created with a TextBox and button placed on it. It also assumes the fontDialog1 has been created. The Font contains the size information but not the color information.

[Visual Basic] 
Protected Sub button1_Click(sender As Object, e As System.EventArgs)
    fontDialog1.ShowColor = True

    fontDialog1.Font = textBox1.Font
    fontDialog1.Color = textBox1.ForeColor

    If fontDialog1.ShowDialog() <> DialogResult.Cancel Then
        textBox1.Font = fontDialog1.Font
        textBox1.ForeColor = fontDialog1.Color
    End If
End Sub 'button1_Click

[C#] 
protected void button1_Click(object sender, System.EventArgs e)
 {
    fontDialog1.ShowColor = true;

    fontDialog1.Font = textBox1.Font;
    fontDialog1.Color = textBox1.ForeColor;

    if(fontDialog1.ShowDialog() != DialogResult.Cancel )
    {
       textBox1.Font = fontDialog1.Font ;
       textBox1.ForeColor = fontDialog1.Color;
    }
 }
 

[C++] 
protected:
void button1_Click(Object* /*sender*/, System::EventArgs* /*e*/)
 {
    fontDialog1->ShowColor = true;

    fontDialog1->Font = textBox1->Font;
    fontDialog1->Color = textBox1->ForeColor;

    if(fontDialog1->ShowDialog() != DialogResult::Cancel )
    {
       textBox1->Font = fontDialog1->Font ;
       textBox1->ForeColor = fontDialog1->Color;
    }
 }
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

FontDialog Members | System.Windows.Forms Namespace | CommonDialog | Font

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.