Advertisement Jump to content
Sign in to follow this  

[.net] Loading Specific Fonts

This topic is 4887 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

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!