C # use a Custom font (obtained from a file)

Source: Internet
Author: User

C # use a Custom font (obtained from a file)
During software development, especially when developing WinForm programs, some special fonts are inevitable to beautify the interface. However, after development, when the program is moved to another machine, the interface is naturally "terrible" because the corresponding fonts may not be installed on these machines "! Of course, you can also use the program to automatically install the appropriate font, but I believe that most people, including me, hate writing messy files to the system disk. So we have this article. Now, you can directly enter the topic. In fact, it is easy to implement in. NET. In System. drawing. text; there is a PrivateFontCollection in the namespace to help us complete related operations. We use the AddFontFile (@ "c: \ font. ttf) method to read the font file into the program, and obtain the FontFamily through the Families [] array attribute of the instance. The Font can be instantiated to complete the Font setting. Code:

1 // path 2 string path = @ "C: \ font. ttf "; 3 // read the font file 4 PrivateFontCollectionpfc = new PrivateFontCollection (); 5 pfc. addFontFile (path); 6 // instantiate the Font 7 Font f = new Font (pfc. families [0], 16); 8 // set the font 9 richTextBox1.Font = f;

 

:

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.