public class FontOperate
{
[DllImport("kernel32.dll", SetLastError = true)]
static extern int WriteProfileString(string lpszSection, string lpszKeyName, string lpszString); [DllImport("user32.dll")]
public static extern int SendMessage(int hWnd,
uint Msg,
int wParam,
int lParam
);
[DllImport("gdi32")]
public static extern int AddFontResource(string lpFileName); public static bool InstallFont(string sFontFileName, string sFontName)
{
string _sTargetFontPath = string.Format(@"{0}\fonts\{1}", System.Environment.GetEnvironmentVariable("WINDIR"), sFontFileName);//系统FONT目录
string _sResourceFontPath = string.Format(@"{0}\Font\{1}", System.Windows.Forms.Application.StartupPath, sFontFileName);//需要安装的FONT目录
try
{
if (!File.Exists(_sTargetFontPath) && File.Exists(_sResourceFontPath))
{
int _nRet;
File.Copy(_sResourceFontPath, _sTargetFontPath);
_nRet = AddFontResource(_sTargetFontPath);
_nRet = WriteProfileString("fonts", sFontName + "(TrueType)", sFontFileName);
}
}
catch
{
return false;
}
return true;
}
}
使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UtilityHelper; namespace LHCity_LMS_Client.Test
{
class Program
{
static void Main(string[] args)
{
FontOperate.InstallFont("simfang.ttf", "simfang");
Console.ReadLine();
}
}
}

  

最新文章

  1. java性能调优工具
  2. BroadcastReceive之ip拨号
  3. 阅读《深入理解JavaScript定时机制》
  4. NOIP2008 普及组T3 传球游戏 解题报告-S.B.S.
  5. read 读取文件内容
  6. 配置VS2010具有代码提示功能
  7. linux常用命令:1文件处理命令
  8. hdu2571
  9. javascript对象定义和操作
  10. LeetCode: Binary Tree Level Order Traversal && Binary Tree Zigzag Level Order Traversal
  11. hdu 2795 线段树
  12. cp命令的编写——浅谈系统调用
  13. Cocos2D-X扫盲之坐标系、锚点
  14. JAVA语法基础(课堂ppt问题总结)
  15. ckeditor 插件
  16. Java虚拟机JVM内存分区及代码执行机制
  17. 201521123106 《Java程序设计》第8周学习总结
  18. UVA 11584 划分回文字串
  19. python中的类机制
  20. [Swift]LeetCode990. 等式方程的可满足性 | Satisfiability of Equality Equations

热门文章

  1. 教你如何利用php.exe运行php文件
  2. js进阶 11-2 jquery属性如何操作
  3. swift菜鸟入门视频教程-01-基础部分
  4. duplicate symbols for architecture
  5. Using Eredis, Redis With Erlang
  6. Eclipse 一直不停 building workspace... 完美解决总结
  7. 【基础练习】【线性DP】codevs1576 最长严格上升子序列题解
  8. HTML_ul无序列表
  9. windows - Cygwin和MinGW有什么区别?(MinGW从Cygwin 1.3.3版本中分离出来)
  10. matlab 求解线性规划问题