C#
[C#] 윈도우에 설치된 폰트 목록 가져오는법 (feat.폰트 저장 위치)
pingu
2021. 12. 6. 16:52
반응형
윈도우에 저장된 폰트 목록이 필요해서 찾아본 방법 기록
윈도우 10 기준, 폰트가 저장되는 폴더 위치 C:\Windows\Fonts
위의 폴더를 방문해보면
한글(hwp)에서 사용할수있는 폰트 목록을 확인할수있다
아래는 C#을 이용하여 윈도우에 설치된 폰트 목록을 가져오고
그걸 텍스트 파일로 출력하는 방법
cs
using System.Drawing.Text; //InstalledFontCollection
using System.IO; //StreamWriter
using System.Windows;
private void getFont2_Click(object sender, RoutedEventArgs e)
{
getFontList();
}
public void getFontList()
{
string installedFont = "";
using (InstalledFontCollection col = new InstalledFontCollection())
{
foreach (System.Drawing.FontFamily fa in col.Families)
{
// 출력 형태 - 폰트 명 : [FontFamily: Name=HY얕은샘물M]
//installedFont += "폰트 명 : " + fa + "\n";
// 출력 형태 - 폰트 명 : HY얕은샘물M
installedFont += "폰트 명 : " + fa.Name + "\n";
}
}
// 폰트 목록을 저장할 폴더 위치
string docPath = @"D:\kay\";
// 위의 docPath에 저장될 폰트 리스트 파일 명 installedFont.txt
using (StreamWriter outputFile = new StreamWriter(System.IO.Path.Combine(docPath, "installedFont.txt")))
{
outputFile.WriteLine(installedFont);
}
}
xaml
<StackPanel Grid.Row="4" Grid.Column="4">
<Button x:Name="getFont2" Click="getFont2_Click">폰트 가져오기</Button>
</StackPanel>
폰트를 가져오는 방법은 InstalledFontCollection 클래스를 사용했다
StreamWriter는 텍스트 파일을 저장할 때 사용
위의 방법이 설치된 폰트를 다 가져오는지 테스트해보려고 폰트 목록을 텍스트 파일로 저장했음
참고 : https://www.c-sharpcorner.com/UploadFile/iersoy/get-all-installed-fonts-in-C-Sharp/
방법: 설치된 글꼴 열거 - Windows Forms .NET Framework
방법: 설치된 글꼴 열거 이 문서의 내용 --> InstalledFontCollection클래스는 FontCollection 추상 기본 클래스에서 상속됩니다. 사용할 수는 InstalledFontCollection 컴퓨터에 설치 된 글꼴을 열거 하는 개체입니
docs.microsoft.com
반응형