이 문서의 내용
InstalledFontCollection 클래스는 FontCollection 추상 기본 클래스에서 상속됩니다. InstalledFontCollection 개체를 사용하여 컴퓨터에 설치된 글꼴을 열거할 수 있습니다. Families 개체의 InstalledFontCollection 속성은 FontFamily 개체의 배열입니다.
다음 예제에서는 컴퓨터에 설치된 모든 글꼴 패밀리의 이름을 나열합니다. 이 코드는 Name 속성에서 반환된 배열에서 각 FontFamily 개체의 Families 속성을 검색합니다. 패밀리 이름이 검색되면 쉼표로 구분된 목록을 형성하기 위해 연결됩니다. 그런 다음, DrawString 클래스의 Graphics 메서드는 사각형에 쉼표로 구분된 목록을 그립니다.
예제 코드를 실행하는 경우 출력은 다음 그림에 표시된 것과 유사합니다.
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)
앞의 예는 Windows Forms에서 사용하도록 설계되었으며 PaintEventArgs의 매개 변수인 e
PaintEventHandler이(가) 필요합니다. 또한 System.Drawing.Text 네임스페이스를 가져와야 합니다.
.NET Desktop feedback 피드백
.NET Desktop feedback 은(는) 오픈 소스 프로젝트입니다. 다음 링크를 선택하여 피드백을 제공해 주세요.