Using custom fonts on a Label on Winforms
Embed the font as a resource (or just include it in the bin directory), and then use the PrivateFontCollection
to load the font (See the AddFontFile
and AddMemoryFont
functions). You then use the font normally like it was installed on the machine.
The PrivateFontCollection class allows
applications to install a private
version of an existing font without
the requirement to replace the system
version of the font. For example, GDI+
can create a private version of the
Arial font in addition to the Arial
font that the system uses.
PrivateFontCollection can also be used
to install fonts that do not exist in
the operating system.
Source
Using custom fonts in my winform labels
Here is the extract (using PrivateFontCollection):
Dim pfc As New PrivateFontCollection()
pfc.AddFontFile("C:\Path To\PALETX3.ttf")
label1.Font = New Font(pfc.Families(0), 16, FontStyle.Regular)
Converted from here: Load And Use Custom Font Without Installing It.
Also check this: Embedding/deploying custom font in .NET app
Change font of a label with custom font
Use the PrivateFontCollection to load the font (See the AddFontFile
and AddMemoryFont
). You then use the font normally for label control.
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile("C:\\Path To\\YourFont.ttf");
label1.Font = new Font(pfc.Families[0], 16, FontStyle.Regular);
C# How to change font of a label
Font.Name
, Font.XYZProperty
, etc are readonly as Font
is an immutable object, so you need to specify a new Font
object to replace it:
mainForm.lblName.Font = new Font("Arial", mainForm.lblName.Font.Size);
Check the constructor of the Font
class for further options.
Looking for the optimal way to use custom font definitions in WinForms application
Simplest way is to bind the font property in the Properties Window to an application setting, which will end up in the app.config file for your application.
Related Topics
Database.Begintransaction VS Transactions.Transactionscope
Using Moq to Mock an Asynchronous Method for a Unit Test
Convert List to Dictionary Using Linq and Not Worrying About Duplicates
Cannot Convert Lambda Expression to Type 'String' Because It Is Not a Delegate Type
How to Delete a Row from Gridview
How to Connect and Use a SQLite Database from C#
Using C# to Authenticate User Against Ldap
String Interpolation VS String.Format
Execute Multiple Queries in Single Oracle Command in C#
How to Select a Random Value from an Enumeration
Is There a Faster Way Than This to Find All the Files in a Directory and All Sub Directories
Determine Operating System in .Net Core
Getting Correct Image Rotation
Are Empty Interfaces Code Smell
Micro Optimization of a 4-Bucket Histogram of a Large Array or List
Converting Integers to Roman Numerals
How to Parse Dates with a Suffix "Th", "St" or "Nd" on the Day of the Month