Share via


Control.DefaultFont 属性

获取控件的默认字体。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Shared ReadOnly Property DefaultFont As Font
用法
Dim value As Font

value = Control.DefaultFont
public static Font DefaultFont { get; }
public:
static property Font^ DefaultFont {
    Font^ get ();
}
/** @property */
public static Font get_DefaultFont ()
public static function get DefaultFont () : Font

属性值

控件的默认 Font。根据用户的操作系统以及系统的本地区域性设置的不同,返回的值也将不同。

异常

异常类型 条件

ArgumentException

默认字体或地区可选字体未安装在客户计算机上。

备注

下表描述了 DefaultFont 根据操作系统和本地区域性返回的值。

系统和/或区域性

字体

Windows NT 4x,日语版

MS UI Gothic, 9 pt

阿拉伯语版 Windows

Tahoma, 8 pt

其他操作系统/区域性

MS Shell Dlg 逻辑字体,通常为“Microsoft San Serif, 8 pt”。

MS Shell Dlg 映射到系统注册表中设置的某种字体。

如果未安装上述字体,则默认字体为“Tahoma, 8 pt”。如果未安装“Tahoma, 8 pt”,DefaultFont 将返回 GenericSansSerif 属性的值

示例

下面的代码示例阐释了如何使用 DefaultBackColorDefaultFontDefaultForeColor 成员。若要运行该示例,请将以下代码粘贴到一个窗体中,让该窗体包含一个名为 ListBox1 的 ListBox。在窗体的构造函数或 Load 事件处理方法中调用 Populate_ListBox 方法。

' The following method displays the default font, 
' background color and foreground color values for the ListBox  
' control. The values are displayed in the ListBox, itself.

Private Sub Populate_ListBox()
    ListBox1.Dock = DockStyle.Bottom

    ' Display the values in the read-only properties 
    ' DefaultBackColor, DefaultFont, DefaultForecolor.
    ListBox1.Items.Add("Default BackColor: " & ListBox.DefaultBackColor.ToString)
    ListBox1.Items.Add("Default Font: " & ListBox.DefaultFont.ToString)
    ListBox1.Items.Add("Default ForeColor:" & ListBox.DefaultForeColor.ToString)

End Sub
// The following method displays the default font, 
// background color and foreground color values for the ListBox  
// control. The values are displayed in the ListBox, itself.

private void Populate_ListBox()
{
    ListBox1.Dock = DockStyle.Bottom;

    // Display the values in the read-only properties 
    // DefaultBackColor, DefaultFont, DefaultForecolor.
    ListBox1.Items.Add("Default BackColor: " + 
        ListBox.DefaultBackColor.ToString());
    ListBox1.Items.Add("Default Font: " + 
        ListBox.DefaultFont.ToString());
    ListBox1.Items.Add("Default ForeColor:" + 
        ListBox.DefaultForeColor.ToString());

}
// The following method displays the default font, 
// background color and foreground color values for the ListBox  
// control. The values are displayed in the ListBox, itself.
void Populate_ListBox()
{
   ListBox1->Dock = DockStyle::Bottom;
   
   // Display the values in the read-only properties 
   // DefaultBackColor, DefaultFont, DefaultForecolor.
   ListBox1->Items->Add( String::Format( "Default BackColor: {0}", ListBox::DefaultBackColor ) );
   ListBox1->Items->Add( String::Format( "Default Font: {0}", ListBox::DefaultFont ) );
   ListBox1->Items->Add( String::Format( "Default ForeColor:{0}", ListBox::DefaultForeColor ) );
}
// The following method displays the default font, 
// background color and foreground color values for the ListBox  
// control. The values are displayed in the ListBox, itself.
private void Populate_ListBox()
{
    listBox1.set_Dock(DockStyle.Bottom);
    // Display the values in the read-only properties 
    // DefaultBackColor, DefaultFont, DefaultForecolor.
    listBox1.get_Items().Add("Default BackColor: " 
        + ListBox.get_DefaultBackColor().ToString());
    listBox1.get_Items().Add("Default Font: " 
        + ListBox.get_DefaultFont().ToString());
    listBox1.get_Items().Add("Default ForeColor:" 
        + ListBox.get_DefaultForeColor().ToString());
} //Populate_ListBox

平台

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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
Control.Font
Font