New to Telerik UI for WinForms? Download free 30-day trial

Custom Fonts

Since R2 2017 Telerik UI for WinForms supports custom fonts. This means that you can use your own fonts without installing them on the local machine.

The following steps will show how you can load and use the new font:

1. First you need to add the font as an embedded resource. Then you can load it with the following code:

var fontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"SamplesCS.Resources.Roboto-Medium.ttf");
var names = Assembly.GetExecutingAssembly().GetManifestResourceNames();

ThemeResolutionService.LoadFont(fontStream);
var font = ThemeResolutionService.GetCustomFont("Roboto Medium");

Dim fontStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SamplesCS.Resources.Roboto-Medium.ttf")
Dim names = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()
ThemeResolutionService.LoadFont(fontStream)
Dim font = ThemeResolutionService.GetCustomFont("Roboto Medium")

Telerik UI for WinForms suite offers the following custom fonts that are embedded in the Telerik.WinControls assembly and they do not need to be loaded explicitly if you want to use some of them:

.ttf file name font name
Roboto-Medium "Roboto"
Roboto-Regular "Roboto Medium"
TelerikWebUI "TelerikWebUI"
WebComponentsIcons "WebComponentsIcons"
Awesome-Brands-Regular "Font Awesome 5 Brands Regular"
Awesome-Regular "Font Awesome 5 Free Regular"
Awesome-Solid "Font Awesome 5 Free Solid"
TelerikFluentIcons "TelerikFluentIcons"

The ThemeResolutionService.GetCustomFont method accepts a font name as a string input parameter and returns a FontFamily instance. Then, it can be used for creating a Font instance and apply it to the Font property of any control.

2. Use the following properties to set the font.

radLabel1.LabelElement.CustomFont = font.Name;
radLabel1.LabelElement.CustomFontSize = 42;
radLabel1.LabelElement.CustomFontStyle = FontStyle.Regular;

radLabel1.LabelElement.CustomFont = font.Name
radLabel1.LabelElement.CustomFontSize = 42
radLabel1.LabelElement.CustomFontStyle = FontStyle.Regular

The important part here is that the above properties are available for the VisualElement ancestors (which are most of our elements).

The below image shows the result:

tpf-custom-fonts001

See Also

In this article