C # install fonts

Source: Internet
Author: User
Using system. windows. forms; using system. runtime. interopservices; using system. io; [dllimport ("kernel32.dll", setlasterror = true)] Static extern int writeprofilestring (string lpszsection, string lpszkeyname, string lpszstring); [dllimport ("user32.dll")] public static extern int sendmessage (INT hwnd, // handle to destination window uint MSG, // message int wparam, // first message parameter int lparam // Second message parameter); [dllimport ("GDI32")] public static extern int addfontresource (string lpfilename); Private void installfont () {string winfontdir = system. environment. getenvironmentvariable ("WINDIR") + "\ fonts"; string fontfilename = "ds-digital bold italic. TTF "; string fontname =" ds-digital bold italic "; int ret; int res; string fontpath; // const int wm_fontchange = 0x001d; // const int H Wnd_broadcast = 0 xFFFF; fontpath = winfontdir + "\" + fontfilename; If (! File. exists (fontpath) {file. copy (system. windows. forms. application. startuppath + "\ ds-digital bold italic. TTF ", fontpath); ret = addfontresource (fontpath); // res = sendmessage (hwnd_broadcast, wm_fontchange, 0, 0); // compiling this sentence in win7 will fail, I don't know if it is a system problem. Here it should be that sending a system message does not affect font installation, So I commented out ret = writeprofilestring ("fonts", fontname + "(TrueType) ", fontfilename );}}

 

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.