Loading a Font File in .NET

System.Drawing.Text.PrivateFontCollection fontcoll = new System.Drawing.Text.PrivateFontCollection();
fontcoll.AddFontFile(@”C:\badrobot\badrobot.ttf”);
System.Drawing.Font font = new System.Drawing.Font(“bad robot”, 20);
this.label1.Font = font;
fontcoll.Dispose();

In WinAPI, the same can be achieved using AddFontResourceEx() and RemoveFontResourceEx().

There is a wonderful resource Win32 to .NET Framework API Mapping which is great if you know a Win32 API and could not find a .NET solution or vice versa.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s