.NET Framework Class Library
FontFamily..::.GetFamilies Method

Returns an array that contains all the FontFamily objects available for the specified graphics context.

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)
Syntax

Visual Basic (Declaration)
Public Shared Function GetFamilies ( _
    graphics As Graphics _
) As FontFamily()
Visual Basic (Usage)
Dim graphics As Graphics
Dim returnValue As FontFamily()

returnValue = FontFamily.GetFamilies(graphics)
C#
public static FontFamily[] GetFamilies(
    Graphics graphics
)
Visual C++
public:
static array<FontFamily^>^ GetFamilies(
    Graphics^ graphics
)
JScript
public static function GetFamilies(
    graphics : Graphics
) : FontFamily[]

Parameters

graphics
Type: System.Drawing..::.Graphics
The Graphics object from which to return FontFamily objects.

Return Value

Type: array<System.Drawing..::.FontFamily>[]()[]
An array of FontFamily objects available for the specified Graphics object.
Exceptions

ExceptionCondition
ArgumentNullException

graphics is nullNothingnullptra null reference (Nothing in Visual Basic).

Examples

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. The code gets an array of the available FontFamily objects, and then draws text to the screen using each of the font families, if the font family supports the regular style.

Visual Basic
Public Sub GetFamilies_Example(ByVal e As PaintEventArgs)

    ' Get an array of the available font families.
    Dim families As FontFamily() = FontFamily.GetFamilies(e.Graphics)

    ' Draw text using each of the font families.
    Dim familiesFont As Font
    Dim familyString As String
    Dim spacing As Single = 0
    Dim family As FontFamily
    For Each family In families
        If (family.IsStyleAvailable(FontStyle.Regular)) Then
            familiesFont = New Font(family, 16)
            familyString = "This is the " + family.Name + " family."
            e.Graphics.DrawString(familyString, familiesFont, _
                Brushes.Black, New PointF(0, spacing))
            spacing += familiesFont.Height
        End If

    Next family
End Sub
C#
public void GetFamilies_Example(PaintEventArgs e)
{
    // Get an array of the available font families.
    FontFamily[] families = FontFamily.GetFamilies(e.Graphics);

    // Draw text using each of the font families.
    Font familiesFont;
    string familyString;
    float spacing = 0;

    foreach (FontFamily family in families)
    {
       if (family.IsStyleAvailable(FontStyle.Regular)) 
        {
            familiesFont = new Font(family, 16);
            familyString = "This is the " + family.Name + " family.";
            e.Graphics.DrawString(
                familyString,
                familiesFont,
                Brushes.Black,
                new PointF(0, spacing));
            spacing += familiesFont.Height;
        }
    }
}
Visual C++
public:
   void GetFamilies_Example( PaintEventArgs^ e )
   {
      // Get an array of the available font families.
      array<FontFamily^>^families = FontFamily::GetFamilies( e->Graphics );

      // Draw text using each of the font families.
      System::Drawing::Font^ familiesFont;
      String^ familyString;
      float spacing = 0;
      IEnumerator^ myEnum = families->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         FontFamily^ family = safe_cast<FontFamily^>(myEnum->Current);
         if ( family->IsStyleAvailable( FontStyle::Regular ) )
         {
            familiesFont = gcnew System::Drawing::Font( family,16 );
            familyString = String::Format( "This is the {0} family.", family->Name );
            e->Graphics->DrawString( familyString, familiesFont, Brushes::Black, PointF(0,spacing) );
            spacing += familiesFont->Height;
         }
      }
   }
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Tags :


Community Content

kwreid
Method marked as "obsolete" on .Net 2.0 x64
I've noticed that this method is marked as "obsolete" on the v2.0sp2 x64 framework, but not on the x86 version of the framework. It's not explained why there's a difference between the x86/x64 frameworks.

[Obsolete("Do not use method GetFamilies, use property Families instead")]

Page view tracker