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

Formatting Blocks

The RadTextBoxControl allow appearance customization of each instance of ITextBlock. This can be easily achieved by subscribing to the FormattingTextBlock event:

Subscribing to TextBlockFormatting event

this.radTextBoxControl1.TextBlockFormatting += this.OnTextBlockFormatting;
this.radTextBoxControl1.Text = "This is important text.";

AddHandler Me.RadTextBoxControl1.TextBlockFormatting, AddressOf Me.OnTextBlockFormatting
Me.RadTextBoxControl1.Text = "This is important text."

The TextBlockFormatting event handler

private void OnTextBlockFormatting(object sender, Telerik.WinControls.UI.TextBlockFormattingEventArgs e)
    TextBlockElement textBlock = e.TextBlock as TextBlockElement;
    if (textBlock != null && e.TextBlock.Text == "important")
        textBlock.ForeColor = Color.Red;

Private Sub OnTextBlockFormatting(sender As Object, e As Telerik.WinControls.UI.TextBlockFormattingEventArgs)
    Dim textBlock As TextBlockElement = TryCast(e.TextBlock, TextBlockElement)
    If textBlock IsNot Nothing AndAlso e.TextBlock.Text = "important" Then
        textBlock.ForeColor = Color.Red
    End If
End Sub

WinForms RadTextBoxControl Formatting Blocks

Notice that the event occurs when the text blocks are repositioned. This happens in different cases: editing, control resizing and etc. Hence, you should subscribe to the event before initializing the Text property.

See Also

In this article