如何安装字体编程(C#) [英] How to install a Font programatically (C#)

查看:280
本文介绍了如何安装字体编程(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法为字体永久添加到Windows 7/8的PC编程? 我已阅读有关AddFontResource DLL导入几个职位,但它似乎并没有工作。

is there a way to permanently add a Font to a Windows 7/8 PC programatically? I have read several posts about the AddFontResource DLL-Import, but it doesn't seem to work.

另外的是,在 MSDN文档说的字体将在计算机重新启动后删除,除非该字体被添加到注册表中。

Besides of that, the MSDN Documentation says the font will be deleted after a restart of the computer, unless the font is added into the registry.

我如何可以安装字体永久?我怎样才能字体添加到注册表?是否总是同一个名字/进入?

How can I install a font permanently? How can I add the font to the registry? Is it always the same name/entry?

我要动态地添加字体上运行,因为我只要用户选择它获取字体。

I have to add the font dynamically on runtime, because I get the font as soon as the user selects it.

备注:我知道如何添加注册表项。我的问题是更多的有关Windows XP,Vista中,7和8以及不同的字体类型之间的兼容性。也许有一种方法来启动它安装的字体对我来说是其它EXE。

Remark: I know how to add a registry entry. My question is more about the compatibility between Windows XP, Vista, 7 and 8 and the different font-types. Maybe there is a way to start an other exe which installs the font for me.

推荐答案

正如你提到的,你可以启动其他可执行文件安装TrueType字体为您服务。我不知道你的具体的用例,但我会跑下来,我知道的方法,也许人会利用你。

As you mentioned, you can launch other executables to install TrueType Fonts for you. I don't know your specific use cases but I'll run down the methods I know of and maybe one will be of use to you.

Windows有一个内置的实用工具名为 fontview.exe ,您可以通过调用简单地调用的Process.Start(路径\到\ file.ttf)任何有效的TrueType字体......假设默认的文件关联。这类似于Windows资源管理器手动启动它。这样做的优点是它真的微不足道,但它仍然需要每个字体的用户交互来安装。据我所知是没有办法来调用这个过程中作为一个参数的安装部分,但即使有,你仍然不得不提升权限和战斗UAC。

Windows has a built-in utility called fontview.exe, which you can invoke simply by calling Process.Start("Path\to\file.ttf") on any valid TrueType Font... assuming default file associations. This is akin to launching it manually from Windows Explorer. The advantage here is it's really trivial, but it still requires user interaction per font to install. As far as I know there is no way to invoke the "Install" portion of this process as an argument, but even if there was you'd still have to elevate permissions and battle UAC.

更有趣的选项是一个叫实用 FontReg ,它取代了德$ pcated fontinst.exe是p $被列入旧版本的Windows。 FontReg ,您可以通过调用可执行文件, /复印编程安装字体的整个目录开关:

The more intriguing option is a utility called FontReg that replaces the deprecated fontinst.exe that was included on older versions of Windows. FontReg enables you to programatically install an entire directory of Fonts by invoking the executable with the /copy switch:

    var info = new ProcessStartInfo()
        {
            FileName = "Path\to\FontReg.exe",
            Arguments = "/copy",
            UseShellExecute = false,
            WindowStyle = ProcessWindowStyle.Hidden

        };

   Process.Start(info);

注意字体必须是在哪里 FontReg.exe 位于根。您还必须具有管理员权限。如果你需要你的字体安装是完全透明的,我建议推出以提升的权限申请并批准了UAC的前面,当你酿出的子进程,你不会需要用户的批准<一个这样href="http://stackoverflow.com/questions/2532769/how-to-start-a-process-as-administrator-mode-in-c-sharp">Permissions东西

Note that the Fonts have to be in the root of wherever FontReg.exe is located. You'll also have to have administrator privileges. If you need your Font installations to be completely transparent, I would suggest launching your application with elevated permissions and approve of the UAC up front, that way when you spawn your child processes you wont need user approval Permissions stuff

这篇关于如何安装字体编程(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆