Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FontDialog.Font Property

Gets or sets the selected font.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public Font Font { get; set; }
/** @property */
public Font get_Font ()

/** @property */
public void set_Font (Font value)

public function get Font () : Font

public function set Font (value : Font)

Property Value

The selected font.

The following code example uses ShowDialog to display a FontDialog. This code requires that a Form has already been created with a TextBox and button placed on it. It also requires that the fontDialog1 has been created. The Font contains the size information but not the color information.

private 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;
    }
 }
 

protected void button1_Click(Object sender, System.EventArgs e)
{
    fontDialog1.set_ShowColor(true);
    fontDialog1.set_Font(textBox1.get_Font());
    fontDialog1.set_Color(textBox1.get_ForeColor());
    if (!(fontDialog1.ShowDialog().Equals(get_DialogResult().Cancel))) {
        textBox1.set_Font(fontDialog1.get_Font());
        textBox1.set_ForeColor(fontDialog1.get_Color());
    }
} //button1_Click

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft