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:

Stream fontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"SamplesCS.Resources.Roboto-Medium.ttf");
string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames();

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

Dim fontStream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SamplesCS.Resources.Roboto-Medium.ttf")
Dim names As String() = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()
ThemeResolutionService.LoadFont(fontStream)
Dim font As FontFamily = 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"

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
Not finding the help you need? Improve this article