Nasıl yapılır: Yüklü Yazı Tiplerini Numaralandırma

sınıfı InstalledFontCollection soyut temel FontCollection sınıftan devralınır. Bilgisayarda yüklü InstalledFontCollection yazı tiplerini numaralandırarak bir nesnesi kullanabilirsiniz. Bir Families nesnenin özelliği bir nesne InstalledFontCollectionFontFamily dizisidir.

Örnek

Aşağıdaki örnek, bilgisayarda yüklü olan tüm yazı tipi ailelerinin adlarını listeler. Kod, özelliği Name tarafından döndürülen FontFamily dizide yer alan her nesnenin özelliğini Families döndürür. Aile adları alınırken, virgülle ayrılmış bir liste oluşturmak için bir eklenir. Ardından DrawString sınıfının Graphics yöntemi, virgülle ayrılmış listeyi dikdörtgene çizer.

Örnek kodu çalıştırsanız, çıkış aşağıdaki çizimde gösterilene benzer:

Screenshot that shows the installed font families.

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);
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 & ",  "
    j += 1
End While

' Draw the large string (list of all families) in a rectangle.
e.Graphics.DrawString(familyList, font, solidBrush, rectF)

Kod Derleniyor

Yukarıdaki örnek, Windows Forms ile birlikte kullanım için tasarlanmıştır ve parametresi PaintEventArgse olan 'i PaintEventHandler gerektirir. Ayrıca, ad alanını içeri aktarmanız System.Drawing.Text gerekir.

Ayrıca bkz.