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.";

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;
    }
}

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.

In this article