728x90
반응형
728x170
▶ Program.cs
using Microsoft.Win32;
using System;
using System.Drawing.Text;
using System.IO;
using System.Runtime.InteropServices;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 폰트 리소스 추가하기 - AddFontResource(fontFilePath)
/// <summary>
/// 폰트 리소스 추가하기
/// </summary>
/// <param name="fontFilePath">폰트 파일 경로</param>
/// <returns>처리 결과</returns>
[DllImport("gdi32.dll")]
private static extern int AddFontResource(string fontFilePath);
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 키 명칭
/// </summary>
private static string _keyName = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts";
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
private static void Main()
{
RegisterFont(@"c:\tvN 즐거운이야기 Bold.ttf");
}
#endregion
#region 폰트 등록하기 - RegisterFont(fontFileName)
/// <summary>
/// 폰트 등록하기
/// </summary>
/// <param name="sourceFontFilePath">소스 폰트 파일 경로</param>
private static void RegisterFont(string sourceFontFilePath)
{
string targetFontFileName = Path.GetFileName(sourceFontFilePath);
string targetFontFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), targetFontFileName);
if(!File.Exists(targetFontFilePath))
{
File.Copy(sourceFontFilePath, targetFontFilePath);
PrivateFontCollection collection = new PrivateFontCollection();
collection.AddFontFile(targetFontFilePath);
string actualFontName = collection.Families[0].Name;
AddFontResource(targetFontFilePath);
Registry.SetValue(_keyName, actualFontName, targetFontFileName, RegistryValueKind.String);
}
}
#endregion
}
}
※ 첨부 프로젝트는 관리자 권한으로 실행되도록 설정되어 있다.
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] SendMessage API를 사용해 컨트롤 클릭하기 (0) | 2018.01.20 |
---|---|
[C#/WINFORM] 특수 키 상태 조사하기 (0) | 2018.01.17 |
[C#/WINFORM] 로또 컨트롤 사용하기 (0) | 2017.12.18 |
[C#/WINFORM] 바이트 배열에서 폰트 만들기 (0) | 2017.12.16 |
[C#/WINFORM] 폰트 설치 여부 구하기 (0) | 2017.11.25 |
[C#/WINFORM] 폰트 설치하기 (0) | 2017.11.23 |
[C#/WINFORM] DataGridView 클래스 : 사용자 열 순서 변경 가능하게 설정하기 (0) | 2017.10.27 |
[C#/WINFORM] DataGridView 클래스 : 사용자 행 삭제시 확인 메시지 표시하기 (0) | 2017.10.27 |
[C#/WINFORM] DataGridView 클래스 : 마우스 오른쪽 버튼을 클릭해 셀 선택하기 (0) | 2017.10.27 |
[C#/WINFORM] DataGridView 클래스 : 좌상단 헤더에 문자열 설정하기 (0) | 2017.10.27 |
[C#/WINFORM] DataGridView 클래스 : 셀 내에서 문자열 선택하기 (0) | 2017.10.27 |
댓글을 달아 주세요