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

Span

The Span class represents an inline object that allows you to display formatted text. A Span can only be used in the context of a Paragraph. As the spans are inline elements they get placed one after another and the text inside them gets wrapped to the next line if the space is insufficient.

This topic will explain you how to:

Use Spans

The Spans can be used only in the context of the Paragraph element. The Paragraph exposes a collection of Inlines, to which the spans can be added.


Section section = new Section();
Paragraph paragraph = new Paragraph();
Span span = new Span("Span declared in code-behind");
paragraph.Inlines.Add(span);
section.Blocks.Add(paragraph);
this.radRichTextEditor1.Document.Sections.Add(section);

Dim section As New Section()
Dim paragraph As New Paragraph()
Dim span As New Span("Span declared in code-behind")
paragraph.Inlines.Add(span)
section.Blocks.Add(paragraph)
Me.radRichTextEditor1.Document.Sections.Add(section)

Add Text to a Span

To specify the text in the Span you can use its Text property.


Section section = new Section();
Paragraph paragraph = new Paragraph();
Span span = new Span("Span declared in code-behind");
paragraph.Inlines.Add(span);
section.Blocks.Add(paragraph);
this.radRichTextEditor1.Document.Sections.Add(section);

Dim section As New Section()
Dim paragraph As New Paragraph()
Dim span As New Span("Span declared in code-behind")
paragraph.Inlines.Add(span)
section.Blocks.Add(paragraph)
Me.radRichTextEditor1.Document.Sections.Add(section)

The Text property of a Span cannot be set to an empty string, as spans that do not contain any text are considered invalid. If you add an empty span in the document programmatically, an exception will be thrown.

Customize a Span

The Span class exposes several properties that allow you to customize the layout of the elements placed underneath it. Here is a list of them:

  • BaselineAlignment - indicates whether the text is Baseline, Subscript or Superscript.

  • FontFamily - represents the name of the text's font.

  • FontSize - represent the size of the text.

  • FontStyle - indicates whether the text should have its style set to italic or to normal.

  • FontWeight - represents the value for the text's weight.

  • ForeColor - represents the foreground color for the text.

  • HighlightColor - represents the background color for the text.

  • Strikethrough - indicates whether the text should be stroke through.

  • UnderlineDecoration - indicates whether the text should be underlined.

See Also

In this article