[.net] Including Fonts as Resources

Started by
2 comments, last by kSquared 18 years, 8 months ago
If I want to use an unusual font in my C# game, I think it would be a good idea to put it in my game resource folder and package it with the game. Is there a way to load a font from a particular directory to use? I don't want users to have to register my fonts with their system.

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

Advertisement
It's possible to bundle a set of application specific fonts with C#. A good starting point is the System.Drawing.Text.PrivateFontCollection class. In particular pay attention to the AddFontFile() method.
You can also compile the font file in the assembly and use it as an embedded resource if you want. Here's some example code on how to load a font embedded in your assembly: http://www.tek-tips.com/faqs.cfm?fid=4747

Bob
Quote:Original post by cyansoft
You can also compile the font file in the assembly and use it as an embedded resource if you want. Here's some example code on how to load a font embedded in your assembly: http://www.tek-tips.com/faqs.cfm?fid=4747

Bob

There's nothing wrong with SiCrane's method, but I think this is the more advisable route. Fonts are resources just like other resources, and you shouldn't have to do extra work to get them to behave the same way. Instead, you should be able to recycle the resource-loading/using code just as if you were retrieving, say, a localized text string or an icon.
- k2"Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ} | {Blog/Journal} | {[email=kkaitan at gmail dot com]e-mail me[/email]} | {excellent webhosting}

This topic is closed to new replies.

Advertisement