P
P
postya2019-12-17 14:36:52
WPF
postya, 2019-12-17 14:36:52

How to assign a custom font to a label programmatically from a folder without installing the font?

There is a label CategoryLabel1
In the program folder there is a folder with fonts.
How to install a custom font for this label from a folder?
I need a programmatic way to use custom fonts from a folder, since in the future these fonts will be in the combobox, and the settings for these fonts will also be in the settings file.
Font folder:
5df8bd5f51973273599608.jpeg
An example of the name of one custom font:
5df8bdbb5ed14741456944.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexV, 2019-12-19
@Av-IT

Everything looks simple
// Create our collection of custom fonts
System.Drawing.Text.PrivateFontCollection privateFontCollection = new System.Drawing.Text.PrivateFontCollection();
// Add your TTF font file to it
privateFontCollection.AddFontFile(@"C:\Temp\gothic.ttf");
// Create a Font object by taking the 0th font from the
Font collection customFont = new Font(privateFontCollection.Families[0], 32, FontStyle.Regular, GraphicsUnit.Pixel);
// We register at the label
CategoryLabel1.Font = customFont;
5dfb3606a1b35345899315.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question