
예제로 창원 단감 폰트 사용..!
ChangwonDangamAsac-Bold_0712.ttf
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Text;
using System.IO;
namespace ApplyFontFromCode
{
public partial class Form1 : Form
{
private PrivateFontCollection privateFontCollection;
public Form1()
{
InitializeComponent();
//해당 리소스가 해제되면 폰트 오류가 발생되므로 전역 변수로 선언 필요.
privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile(Path.Combine(Application.StartupPath, "ChangwonDangamAsac-Bold_0712.ttf"));
SetControlFont(this);
}
private void SetControlFont (Control parent)
{
foreach (Control child in parent.Controls) //모든 하위 컨트롤들에 대해서 적용시켜줍니다.
{
child.Font = new Font(privateFontCollection.Families[0], child.Font.Size, child.Font.Style);
if (child.Controls.Count > 0) //panel, groupbox 와 같이 하위 컨트롤이 더 있는 경우도 적용시켜줍니다.
{
SetControlFont(child);
}
}
}
}
}'C# > Windows Form' 카테고리의 다른 글
| [C# Windows Form] FormBorderStyle None 에 대한 기본 클래스 (0) | 2025.11.28 |
|---|---|
| [C# Windows Form] Custom Button Class - 이미지 버튼 생성 (hover, press, normal, focus) (0) | 2025.11.27 |
| [C# Windows Form] 섬네일 만들기 (ListView, ListBox) (0) | 2025.11.17 |
| [C# Windows Form] ZipFile 다루기 - 압축 및 해제 (0) | 2025.10.06 |
| [C# Windows Form] 비동기 Custom Form 종료, 파일 열기, 프린트 등 창 닫기 (BlockingCollection - queue) (0) | 2025.09.08 |