How to load a font from a file in VB and C #?

I want to load a font into my VB Form program from a file.

For example: My font is in the same folder of my .exe program, and I want it to remain an external resource (which we can replace so that it changes the entire font of the program).

+6
source share
1 answer

Here is an example of how you can do this in C #:

System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection(); privateFonts.AddFontFile("C:\\Documents and Settings\\somefont.ttf"); System.Drawing.Font font = new Font(privateFonts.Families[0], 12); label1.Font = font; 

Or, in VB.NET:

 Dim privateFonts As New System.Drawing.Text.PrivateFontCollection() privateFonts.AddFontFile("C:\Documents and Settings\somefont.ttf") Dim font As New System.Drawing.Font(privateFonts.Families(0), 12) label1.Font = font 

See IT for more details.

+15
source

Source: https://habr.com/ru/post/955116/


All Articles