Fonts
RadRichTextBox uses different font families to render the text inside. This article describes how the default font families are loaded and how you can register custom ones.
Default Fonts
When initializing, RadRichTextBox loads all the fonts installed on the current machine so they can be used inside the content. The API enables you to work with these fonts by directly assigning a FontFamily instance to the desired property. Example 1 shows a sample usage of an already available font.
Example 1: Setting font to a Span
Span span = new Span();
span.FontFamily = new FontFamily("Arial");
Dim span As Span = New Span()
span.FontFamily = New FontFamily("Arial")
To ensure the font you would like to use is registered and available for the control, you can use the HasRegisteredFontFamily() method of FontManager.
Example 2: Ensuring font is registered before using it
FontFamily fontFamily = new FontFamily("Arial");
if (FontManager.HasRegisteredFontFamily(fontFamily))
{
Span span = new Span();
span.FontFamily = fontFamily;
}
Dim fontFamily As FontFamily = New FontFamily("Arial")
If FontManager.HasRegisteredFontFamily(fontFamily) Then
Dim span As Span = New Span()
span.FontFamily = fontFamily
End If
Through the FontManager class, you can also traverse all the fonts that are currently registered and can be used in RadRichTextBox.
Example 3: Obtain all registered fonts
RegisteredFonts registeredFonts = FontManager.GetRegisteredFonts();
Dim registeredFonts As RegisteredFonts = FontManager.GetRegisteredFonts()
Custom Fonts
You might encounter a case where specific font is not installed on the machine. In this scenario, you can register it as a custom one and ensure that the users have access to it and can use it. All you need to do is to invoke the RegisterFont() method.
Example 4: Register font
FontManager.RegisterFont(new FontFamily("Helvetica"));
FontManager.RegisterFont(New FontFamily("Helvetica"))
Once you have the font registered, you can use it as you would do with any other font family.
In case you need to remove a font so that it cannot be used in the control, RadRichTextBox enables you to achieve that by simply unregistering that font.
Example 5: Unregister font
FontManager.UnregisterFont(new FontFamily("Helvetica"));
FontManager.UnregisterFont(New FontFamily("Helvetica"))