New to Telerik UI for WinForms? Start a free 30-day trial
Setting Default Cell Content Alignment in RichTextEditor Programmatically
Updated on Mar 16, 2026
| Product Version | Product | Author |
|---|---|---|
| 2026.1.210 | RadRichTextEditor for WinForms | Dinko Krastev |
Description
In this KB article, we will demonstrate how to set text alignment to left and centered programmatically.
Solution
To set all table cell content alignment to left and centered:
- Retrieve the table from the document using
EnumerateChildrenOfType<Table>(). - Clear the current selection.
- Set the selection to cover the entire table.
- Use the
RadDocumentEditorto apply the alignment changes. - Clear the selection after applying the alignment.
Here is the sample code:
C#
var tables = richTextEditor.Document.EnumerateChildrenOfType<Table>();
var table = tables.FirstOrDefault();
richTextEditor.Document.Selection.Clear();
var start = new DocumentPosition(richTextEditor.Document);
start.MoveToDocumentElementStart(table);
richTextEditor.Document.Selection.AddSelectionStart(start);
var end = new DocumentPosition(richTextEditor.Document);
end.MoveToDocumentElementEnd(table);
richTextEditor.Document.Selection.AddSelectionEnd(end);
RadDocumentEditor editor = new RadDocumentEditor(richTextEditor.Document);
editor.ChangeTableCellContentAlignment(RadTextAlignment.Left, Telerik.WinForms.Documents.Layout.RadVerticalAlignment.Center);
richTextEditor.Document.Selection.Clear();