Installing a TT-Font

  • Thread starter Thread starter Johan
  • Start date Start date
J

Johan

Hi

How would I go about installing a font file on WinXP?

I have tried this and it won't get installed properly,

private void installFont()
{
File.Copy( Application.StartupPath+"\\Lucon1.ttf",
this.fontDir+"\\Lucon1.ttf", true );
key.SetValue( "Lucida Console ANSI
TrueType)", "Lucon1.ttf");
SendMessage((System.IntPtr)HWND_BROADCAST,
WM_FONTCHANGE, 0, 0);
}
 
Johan,

Does your app include a Setup Project? Because if you build a setup project
for your app, you can add fonts to it and when the user installs it the
fonts will be automatically installed, and removed upon un-install.

JIM
 
Yes I know I could go that way, but I was kind of hoping to just end up with
one exe-file for the application without the need for installation...

/Johan
 
Hi,

You should rather use the GDI Function AddFontResource by P-Invoke,
shouldn't you? I was searching for sample code demonstrating how to load
the font out of a ttf file but all i found were some functions, one of
them is AddFontResource.

This could be your signature:

[DllImport("gdi32")]
static extern int AddFontResource(string lpszFilename);
// returns the number of fonts installed


This could be your Add font function:

public static bool AddFont(string filename)
{
if (System.IO.File.Exists(filename))
{
// returns true if (>=1) font is installed
return (AddFontResource(filename) != 0);
}
return false;
}

I do not know whether it does the right thing for you, but you may givbe
it a try if it does

Greets,

AS
 
Oh no, it doesn't work...
Perhaps system font table is something different than system fonts or it
installs the font for the calling app only.
 
Back
Top