Share via


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

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

(继承自 FontCollection)

方法

Dispose()

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

(继承自 FontCollection)
Dispose(Boolean)

释放由 FontCollection 占用的非托管资源,还可以另外再释放托管资源。

(继承自 FontCollection)
Equals(Object)

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

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

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

(继承自 Object)

适用于

另请参阅