c#代码安装字体文件
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();
}
}
}
c#代码安装字体文件的更多相关文章
- Linux服务器上安装openoffice,以及安装字体文件
1.安装openoffice (1)将openoffice的linux安装包放到linux指定的文件下(一般放在opt下) (2)在安装包的目录下执行命令:tar -zxvf 对应的压缩包名字 (3) ...
- Linux安装字体文件
登录生成验证码的时候使用了monaco.ttf字体,没有安装字体的情况下,会报错:can't open resource Linux安装字体的方式其实很简单,就是调用fc-cache -f -v命令, ...
- 用批处理,批量安装字体文件 (Erector.bat)
@echo off color 0A title 字体安装器 Powered by Cheney_Yang cls xcopy /y "Fonts\*.ttf" "%wi ...
- 代码安装apk文件
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.fromFile(file); in ...
- 使用VBSCRIPT安装字体
根据新系统要求,经常要部署一些原来系统里没有的字体,原先我为了图省事经常会要求用户手动安装字体文件,虽然Windows的易用性做得相当不错,但是仍然要照顾一些不会安装字体的人,其实把这些字体打包进安装 ...
- windows系统下,在C#程序中自动安装字体
在Windows系统中,原有自带的字体样式有限,有时候我们的程序会使用到个别稀有或系统不自带的字体.因此我们需要将字体打包到程序中,当程序启动时,检测系统是否有该字体,如果没有则安装该字体,也可以动态 ...
- 零基础学python之函数与模块(附详细的代码和安装发布文件过程)
代码重用——函数与模块 摘要:构建函数,创建模块,安装发布文件,安装pytest和PEP 8插件,确认PEP8兼容性以及纠错 重用代码是构建一个可维护系统的关键. 代码组是Python中对块的叫法. ...
- Android 在代码中安装 APK 文件
废话不说,上代码 private void install(String filePath) { Log.i(TAG, "开始执行安装: " + filePath); File a ...
- WPF 将字体文件 添加到 资源文件,并在后台代码使用
先看结果 1.将字体文件,导入到资源文件,如: 添加后,自动生成 2.在窗体xaml中添加如: 3.在xaml窗体对应的cs文件中,为TextBlock指定字段 创建一个字段对象,并指定字体文件的所在 ...
随机推荐
- 【U205】最大值
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 找到一个数组的最大值的一种方法是从数组开头从前到后对数组进行扫描,令max=a[0](数组下表从0.. ...
- 【codeforces 755A】PolandBall and Hypothesis
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- [React] Use React.cloneElement to Extend Functionality of Children Components
We can utilize React.cloneElement in order to create new components with extended data or functional ...
- DOM中Event 对象如何使用
DOM中Event 对象如何使用 一.总结 一句话总结: 1.将event作为参数传递进来,然后就可以调用event对象的各种属性和方法了. <body onmousedown="wh ...
- 64位Oracle11g自带的sqldevelper无法启动
原因:选择的jdk有问题 解决方法:由于Oracle自带的Sqldeveloper只支持32位的java运行环境,如果本机安装64位jdk,需要手动更改SqlDeveloper路径到32位的jdk即可 ...
- LaunchImage启动黑屏-模拟器可以,但是真机黑屏
名称和尺寸都是对的,就是不显示.结果美工重新做一张图片就行了,想了半天都没想到是图片本身等问题啊
- TensorFlow: couldn’t open CUDA library cupti64_80.dll、InternalError: Blas SGEMM launch failed
1. couldn't open CUDA library cupti64_80.dll Win10 TensorFlow(gpu)安装详解 在资源管理器中查询 cupti64_80.dll 的位置. ...
- range 的实现细节(start、end、step)(左闭右开区间)
range(int start, int end, int step); 返回的区间是 [start, end) 要求步长为 step,三个参数均为整数, 在底层实现时,最终返回的区间元素的数目应当为 ...
- JavaCPP 技术使用经验总结
本文是对 JNI 技术的一个补充方法,提出了替换 JNI.JNA 的一种开源技术.首先对 JavaCPP 技术进行简单介绍及对应于其他现有方案的介绍.对比.接下来,通过一个简单的示例让大家了解 Jav ...
- 使用HAXM为QEMU for Windows加速
QEMU是一款支持多种CPU的虚拟化软件,本身基于软件虚拟化,效率不高,在linux下可以基于KVM加速,据说可以获得接近物理机的性能.网上有很多关于QEMU+KVM的使用说明,但是KVM仅用于lin ...