C # Place the personalized font in the resource file for the program to call

Source: Internet
Author: User

Most of the time, the customer's computer has not installed this font. For example, XP computers do not have this font. How can we embed this font into the resource file so that the program can call it, can be displayed normally on XP? WPF implementation method: Find the Quartz MS. TTF font file in the C: \ Windows \ Fonts \ folder, add it to the Resources of the WPF project, and set it to the Resource type. Add a Style in XAML to reference this Font Resource <Window. resources> <Style x: Key = "QuartzMSFont"> <Setter Property = "TextElement. fontFamily "Value =" Resources/# Quartz MS "/> </Style> </Window. resources> call method: <TextBlock Style = "{DynamicResource QuartzMSFont}" Text = "1234567"/> note that the name of "# Quartz MS" of Value must be consistent with the actual name of the font file! If you double-click the font file Quartz MS. TTF, you can find the font name in the font file (as shown in) font name C # Winform implementation method is relatively simple, you can use the following code:

System.Drawing.Text.PrivateFontCollection privateFonts = new    System.Drawing.Text.PrivateFontCollection();  privateFonts.AddFontFile("C:\\Documents and Settings\\QuartzMS.ttf");  System.Drawing.Font font = new Font(privateFonts.Families[0], 12);  this.label1.Font = font;  

 

 

Related Article

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.