Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
FontFamily Class
 GetFamilies Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.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)
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.
ExceptionCondition
ArgumentNullException

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

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;
         }
      }
   }

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Method marked as "obsolete" on .Net 2.0 x64      kwreid   |   Edit   |   Show History
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")]
Tags What's this?: .net (x) 2.0 (x) obsolete (x) sp2 (x) x64 (x) Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker