Uredi

Deli z drugimi prek


InstalledFontCollection Class

Definition

Represents the fonts installed on the system. This class cannot be inherited.

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
Inheritance
InstalledFontCollection

Examples

The following example shows how to get a list of fonts that support the regular FontStyle.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler.

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

Remarks

The InstalledFontCollection allows you to get a list of fonts families that are installed on the computer running the application with its Families property. For additional information on fonts and text, including example code, see Using Fonts and Text.

Do not use the InstalledFontCollection class to install a font to Windows. Instead use the GDI AddFontResource function. An InstalledFontCollection object sees only fonts that are installed in Windows before the object is created.

Note

In .NET 6 and later versions, the System.Drawing.Common package, which includes this type, is only supported on Windows operating systems. Use of this type in cross-platform apps causes compile-time warnings and run-time exceptions. For more information, see System.Drawing.Common only supported on Windows.

Constructors

InstalledFontCollection()

Initializes a new instance of the InstalledFontCollection class.

Properties

Families

Gets the array of FontFamily objects associated with this FontCollection.

(Inherited from FontCollection)

Methods

Dispose()

Releases all resources used by this FontCollection.

(Inherited from FontCollection)
Dispose(Boolean)

Releases the unmanaged resources used by the FontCollection and optionally releases the managed resources.

(Inherited from FontCollection)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also