Sign in to follow this  

[.net] Loading Specific Fonts

Recommended Posts

Is there an easy way to package a TrueType (.ttf) font file with my game and load that file in such a way that I can display it in all the .Net controls and also using Graphics.DrawString?

Share this post

Link to post
Share on other sites
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):

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

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