This article tells you to load fonts from files. Use fontfamily to display the specified TTF display font in WPF
If there are fonts in C:\Projects\MyProj\free3of9.ttf
, you can use PrivateFontCollection to add fonts.
The following code can use the local Free3of9.ttf, note that the added FontFamily is required to know the font name, and the incoming privatefontcollection can only be used.
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);
Another way is to remove the suffix name of the font, directly written in the FontFamily, I prefer to use the following method
FontFamily fontFamily = new FontFamily(@"C:\Projects\MyProj\#free3of9");
https://stackoverflow.com/a/24022783/6116637
This work is licensed under the Creative Commons Attribution-NonCommercial use-Share 4.0 International license agreement in the same way. Welcome to reprint, use, republish, but be sure to keep the article Attribution Lindesi (including Link: http://blog.csdn.net/lindexi_gd), not for commercial purposes, based on the modified works of this article must be issued with the same license. If you have any questions, please contact me.
WPF loading fonts from files