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

## 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 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):

[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 on other sites
Private Fonts

When you set the font of a form the controls 'inherit' the font.

Cheers

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633368
• Total Posts
3011531
• ### Who's Online (See full list)

There are no registered users currently online

×