Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  




           


Installing Fonts in C#
The following C# code will install a font on a 32 bit machine.

int Ret;
int Res;
string FontPath;
const int WM_FONTCHANGE = 0x001D;
const int HWND_BROADCAST = 0xffff;
FontPath = WinFontDir + "\" + FontFileName;
Ret = FontInstall.AddFontResource(FontPath);
Res = FontInstall.SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
Ret = FontInstall.WriteProfileString("fonts", FontName + " (TrueType)", FontFileName);



With of course, the API functions:

[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);

Created By: amos 3/20/2006 12:13:00 AM
Updated: 3/12/2023 5:11:45 AM


 Comments:
 > Guest 2/3/2009 4:52:05 AM
not working in asp .net page
 > Guest 10/6/2009 7:54:44 AM
how to get font name from font file?
 > Guest 6/27/2011 4:44:21 AM
Th code is not working in asp.net 3.5