Share via


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

InstalledFontCollection sınıfı soyut temel sınıfından FontCollection devralır. Bilgisayarda yüklü yazı tiplerini listelemek için bir InstalledFontCollection nesne kullanabilirsiniz. Bir FamiliesInstalledFontCollection nesnenin özelliği bir nesne dizisidir FontFamily .

Örnek

Aşağıdaki örnekte, bilgisayarda yüklü olan tüm yazı tipi ailelerinin adları listelenmiştir. Kod, özelliği tarafından döndürülen dizideki her FontFamily nesnenin Families özelliğini alırName. Aile adları alınırken, virgülle ayrılmış bir liste oluşturmak üzere birleştirilir. DrawString Ardından sınıfının yöntemi Graphics virgülle ayrılmış listeyi bir dikdörtgene çizer.

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

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 kullanılmak üzere tasarlanmıştır ve parametresi PaintEventHandlerolan öğesini gerektirir.PaintEventArgse Buna ek olarak, ad alanını System.Drawing.Text içeri aktarmanız gerekir.

Ayrıca bkz.