Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load fonts from file on a C# application

Tags:

I wish to load and use a font to a desktop application in C#. It's that possible without installing the font on the system?

It's a kind of question like this but not from a DLL. I want to load from font file.

like image 252
FerranB Avatar asked Feb 13 '09 06:02

FerranB


People also ask

How do I add Fonts to C drive?

To activate a font on any version of Windows, navigate to Computer ▸ Local Disk (C:) ▸ Windows ▸ Fonts. Locate the folder you've expanded from the downloaded . zip file, and drag the font files into the Fonts folder.

How do you extract a font from a file?

If the font files are zipped, unzip them by right-clicking the . zip folder and then clicking Extract. Now you'll see the available TrueType and OpenType font files: Right-click the fonts you want, and click Install.

How do I upload a font file?

Search for Fonts in settings. Click on the Fonts Folder to open the Font folder. Drag and Drop or Copy and Paste the unzipped fonts files into the Fonts folder to install.

How do I load a TTF font?

To install the TrueType font in Windows:Click on Start, Select, Settings and click on Control Panel. Click on Fonts, click on File in the main tool bar and select Install New Font. Select the folder where the font is located. The fonts will appear; select the desired font that is titled TrueType and click on OK.


2 Answers

There's a class System.Drawing.Text.PrivateFontCollection in System.Drawing.dll which can manage fonts on a per application basis.

All you do is that you maintain this collection within your app and you add fonts through AddFontFile or AddMemoryFont and you'll then be able to use that font as if it was installed on your system.

It's like installing the font for the application only. The font will be uninstalled once the process terminates.

like image 198
John Leidegren Avatar answered Sep 28 '22 12:09

John Leidegren


Load a font from disk, stream or byte array

Try this...

The blog describes how to use the FontCollection classes.

like image 31
Adrian Hum Avatar answered Sep 28 '22 13:09

Adrian Hum