다음을 통해 공유


방법: 설치된 글꼴 열거

InstalledFontCollection 클래스는 FontCollection 추상 기본 클래스에서 상속됩니다. InstalledFontCollection 개체는 컴퓨터에 설치되어 있는 글꼴을 열거하는 데 사용할 수 있습니다. InstalledFontCollection 개체의 Families 속성은 FontFamily 개체의 배열입니다.

예제

아래 예제에서는 시스템에 설치되어 있는 모든 글꼴 패밀리의 이름을 나열합니다. 해당 코드에서는 Families 속성에서 반환된 배열에 있는 각 FontFamily 개체의 Name 속성을 검색하고 검색된 패밀리 이름을 연결하여 쉼표로 분리된 목록을 만듭니다. 그런 다음 Graphics 클래스의 DrawString 메서드가 쉼표로 구분된 목록을 사각형 안에 그립니다.

예제 코드를 실행하면 다음 그림과 비슷한 결과가 나타납니다.

설치된 글꼴

        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)

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

코드 컴파일

앞의 예제는 Windows Forms에서 사용해야 하며 PaintEventHandler의 매개 변수인 PaintEventArgs e를 필요로 합니다. 또한 System.Drawing.Text 네임스페이스를 가져와야 합니다.

참고 항목

기타 리소스

글꼴 및 텍스트 사용