c#代码安装字体文件
2024-08-31 23:41:01
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();
}
}
}
最新文章
- java性能调优工具
- BroadcastReceive之ip拨号
- 阅读《深入理解JavaScript定时机制》
- NOIP2008 普及组T3 传球游戏 解题报告-S.B.S.
- read 读取文件内容
- 配置VS2010具有代码提示功能
- linux常用命令:1文件处理命令
- hdu2571
- javascript对象定义和操作
- LeetCode: Binary Tree Level Order Traversal &;&; Binary Tree Zigzag Level Order Traversal
- hdu 2795 线段树
- cp命令的编写——浅谈系统调用
- Cocos2D-X扫盲之坐标系、锚点
- JAVA语法基础(课堂ppt问题总结)
- ckeditor 插件
- Java虚拟机JVM内存分区及代码执行机制
- 201521123106 《Java程序设计》第8周学习总结
- UVA 11584 划分回文字串
- python中的类机制
- [Swift]LeetCode990. 等式方程的可满足性 | Satisfiability of Equality Equations
热门文章
- 教你如何利用php.exe运行php文件
- js进阶 11-2 jquery属性如何操作
- swift菜鸟入门视频教程-01-基础部分
- duplicate symbols for architecture
- Using Eredis, Redis With Erlang
- Eclipse 一直不停 building workspace... 完美解决总结
- 【基础练习】【线性DP】codevs1576 最长严格上升子序列题解
- HTML_ul无序列表
- windows - Cygwin和MinGW有什么区别?(MinGW从Cygwin 1.3.3版本中分离出来)
- matlab 求解线性规划问题