通过


InstalledFontCollection 类

定义

表示系统上安装的字体。 无法继承此类。

public ref class InstalledFontCollection sealed : System::Drawing::Text::FontCollection
public sealed class InstalledFontCollection : System.Drawing.Text.FontCollection
type InstalledFontCollection = class
    inherit FontCollection
Public NotInheritable Class InstalledFontCollection
Inherits FontCollection
继承
InstalledFontCollection

示例

以下示例演示如何获取支持常规 FontStyle字体的字体列表。

下面的代码示例旨在与 Windows 窗体一起使用,它需要 PaintEventArgse,这是事件处理程序的参数 Paint

InstalledFontCollection ifc = new InstalledFontCollection();
private void EnumerateInstalledFonts(PaintEventArgs e)
{
    FontFamily[] families = ifc.Families;
    float x = 0.0F;
    float y = 0.0F;
    for (int i = 0; i < ifc.Families.Length; i++)
    {
        if (ifc.Families[i].IsStyleAvailable(FontStyle.Regular))
        {
            e.Graphics.DrawString(ifc.Families[i].Name, new Font(ifc.Families[i], 12), 
                Brushes.Black, x, y);
            y += 20;
            if (y % 700 == 0)
            {
                x += 140;
                y = 0;
            }
        }
    }
}
    Private ifc As New InstalledFontCollection()
    
Private Sub EnumerateInstalledFonts(ByVal e As PaintEventArgs)
      Dim families As FontFamily() = ifc.Families
      Dim x As Single = 0.0F
      Dim y As Single = 0.0F
        For i As Integer = 0 To ifc.Families.Length - 1
              If ifc.Families(i).IsStyleAvailable(FontStyle.Regular) Then
                e.Graphics.DrawString(ifc.Families(i).Name, New Font(ifc.Families(i), 12),  _ 
          Brushes.Black, x, y)
                y += 20
                If y Mod 700 = 0 Then
                      x += 140
                      y = 0
                    End If
              End If
        Next
   End Sub

注解

这样 InstalledFontCollection ,就可以获取运行应用程序 Families 及其属性的计算机上安装的字体系列列表。 有关字体和文本的其他信息,包括示例代码,请参阅 “使用字体和文本”。

不要使用该 InstalledFontCollection 类将字体安装到 Windows。 请改用 GDI AddFontResource 函数。 对象 InstalledFontCollection 仅看到在创建对象之前安装在 Windows 中的字体。

注意

在 .NET 6 及更高版本中,包含此类型的 System.Drawing.Common 包 仅支持在 Windows 操作系统上运行。 在跨平台应用中使用此类型会导致编译时警告和运行时异常。 有关详细信息,请参阅 仅在 Windows 上支持的 System.Drawing.Common。

构造函数

名称 说明
InstalledFontCollection()

初始化 InstalledFontCollection 类的新实例。

属性

名称 说明
Families

获取与此FontCollection关联的对象的数组FontFamily

(继承自 FontCollection)

方法

名称 说明
Dispose()

释放由此 FontCollection使用的所有资源。

(继承自 FontCollection)
Dispose(Boolean)

释放由托管资源使用 FontCollection 的非托管资源,并选择性地释放托管资源。

(继承自 FontCollection)
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅