Sign in to follow this  

[.net] Loading Specific Fonts

This topic is 4479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not sure if you can do it using only .NET, but the Win32 way involves calling AddFontResourceEx with the font filename and FR_PRIVATE, after which you can create the font as if it were installed in the fonts folder. You can get the P/Invoke definition here.

All the relevant code in C# (untested):


[DllImport("gdi32.dll")]
static extern int AddFontResourceEx(string lpszFilename, uint fl, IntPtr pdv);

const uint FR_PRIVATE = 0x10;

Font MyLoadFont()
{
AddFontResourceEx("myfont.ttf", FR_PRIVATE, IntPtr.Zero);
return new Font("My Font Name", 8.2f);
}

Share this post


Link to post
Share on other sites

This topic is 4479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this