Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
La classe InstalledFontCollection eredita dalla classe base astratta FontCollection. È possibile utilizzare un oggetto InstalledFontCollection per enumerare i caratteri installati sul computer. La proprietà Families di un oggetto InstalledFontCollection è una matrice di oggetti FontFamily.
Con l'esempio riportato di seguito vengono elencati i nomi di tutti i gruppi di caratteri installati sul computer. Viene recuperata la proprietà Name di ciascun oggetto FontFamily nella matrice restituita dalla proprietà Families. Una volta recuperati, i nomi dei gruppi vengono concatenati per formare un elenco separato da virgole. Quindi, tramite il metodo DrawString della classe Graphics, l'elenco viene visualizzato in un rettangolo.
Dim fontFamily As New FontFamily("Arial")
Dim font As New Font( _
fontFamily, _
8, _
FontStyle.Regular, _
GraphicsUnit.Point)
Dim rectF As New RectangleF(10, 10, 500, 500)
Dim solidBrush As New SolidBrush(Color.Black)
Dim familyName As String
Dim familyList As String = ""
Dim fontFamilies() As FontFamily
Dim installedFontCollection As New InstalledFontCollection()
' Get the array of FontFamily objects.
fontFamilies = installedFontCollection.Families
' The loop below creates a large string that is a comma-separated
' list of all font family names.
Dim count As Integer = fontFamilies.Length
Dim j As Integer
While j < count
familyName = fontFamilies(j).Name
familyList = familyList + familyName
familyList = familyList + ", "
End While
' Draw the large string (list of all families) in a rectangle.
e.Graphics.DrawString(familyList, font, solidBrush, rectF)
[C#]
FontFamily fontFamily = new FontFamily("Arial");
Font font = new Font(
fontFamily,
8,
FontStyle.Regular,
GraphicsUnit.Point);
RectangleF rectF = new RectangleF(10, 10, 500, 500);
SolidBrush solidBrush = new SolidBrush(Color.Black);
string familyName;
string familyList = "";
FontFamily[] fontFamilies;
InstalledFontCollection installedFontCollection = new InstalledFontCollection();
// Get the array of FontFamily objects.
fontFamilies = installedFontCollection.Families;
// The loop below creates a large string that is a comma-separated
// list of all font family names.
int count = fontFamilies.Length;
for(int j = 0; j < count; ++j)
{
familyName = fontFamilies[j].Name;
familyList = familyList + familyName;
familyList = familyList + ", ";
}
// Draw the large string (list of all families) in a rectangle.
e.Graphics.DrawString(familyList, font, solidBrush, rectF);
Se si esegue il codice precedente l'output sarà analogo a quello mostrato nell'illustrazione seguente.
.png)