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

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 its default fonts so they can be used inside the content. Below is a list of all the loaded font families:

  • Arial
  • Arial Black
  • Calibri
  • Comic Sans MS
  • Courier New
  • Georgia
  • Lucida Sans Unicode
  • Times New Roman
  • Trebuchet MS
  • Verdana

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")) 

When registering custom fonts in Silverlight, you might encounter a limitation where a TextBlock, using that font-family shall be added in the visual tree in order the font to be applied.

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")) 

See Also

In this article
Not finding the help you need? Improve this article