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()
Dim graphics As Graphics
Dim returnValue As FontFamily()
returnValue = FontFamily.GetFamilies(graphics)
public static FontFamily[] GetFamilies(
Graphics graphics
)
public:
static array<FontFamily^>^ GetFamilies(
Graphics^ graphics
)
public static function GetFamilies(
graphics : Graphics
) : FontFamily[]
| Exception | Condition |
|---|
| 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.
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
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;
}
}
}
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
Reference