Installing a TT-Font

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);
}
 
J

James

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
 
J

Johan

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
 
?

=?ISO-8859-15?Q?Andreas_Sch=F6neck?=

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
 
?

=?ISO-8859-15?Q?Andreas_Sch=F6neck?=

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top