WPF loading fonts from files

Source: Internet
Author: User
Tags creative commons attribution

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.