Control.DefaultFont 属性

定义

获取控件的默认字体。

C#
public static System.Drawing.Font DefaultFont { get; }

属性值

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

例外

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

示例

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

C#

// 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());
}

注解

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

系统/和或区域性 字体
Windows NT 4x,日语版本 MS UI 哥特式,9 磅。
阿拉伯语 Windows 塔霍马,8分。
其他操作系统/区域性 MS Shell Dlg 逻辑字体,通常为 Microsoft San Serif 8 磅。

MS Shell Dlg 映射到系统注册表中的字体集。

如果未安装以前的字体,则默认字体为 Tahoma,8 磅。 如果未安装 8 磅的 Tahoma,DefaultFont则返回 属性的值GenericSansSerif

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅