本文告诉大家从文件加载字体。在wpf 使用 fontfamily 显示指定的 ttf 显示字体。
假如有字体在 C:\Projects\MyProj\free3of9.ttf
,可以使用 PrivateFontCollection 添加字体。
下面的代码就可以使用本地的 free3of9.ttf ,需要注意添加的 FontFamily 是需要知道字体名,和传入 PrivateFontCollection 才可以使用。
PrivateFontCollection collection = new PrivateFontCollection();
collection.AddFontFile(@"C:\Projects\MyProj\free3of9.ttf");
FontFamily fontFamily = new FontFamily("Free 3 of 9", collection);
Font font = new Font(fontFamily, height);
另一个方法是去掉字体的后缀名,直接写在 FontFamily ,我比较希望使用下面的方法
FontFamily fontFamily = new FontFamily(@"C:\Projects\MyProj\#free3of9");
https://stackoverflow.com/a/24022783/6116637
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有