Editing and formatting
Text selection
// Select all
RichEditor1.SelectAll;
// Select a range (character offset, length)
RichEditor1.Select(10, 5);
// Deselect
RichEditor1.ClearSelection;
Character formatting
Apply formatting to the current selection or the cursor position (affects new typing):
| Property | Type | Description |
|---|---|---|
Bold |
Boolean |
Bold text |
Italic |
Boolean |
Italic text |
Underline |
Boolean |
Underline |
StrikeThrough |
Boolean |
Strikethrough |
SuperScript |
Boolean |
Superscript |
SubScript |
Boolean |
Subscript |
FontName |
String |
Font family |
FontSize |
Single |
Font size in points |
FontColor |
TAlphaColor |
Text color |
// Make selected text bold and red
RichEditor1.Bold := True;
RichEditor1.FontColor := gcRed;
Reading the same properties returns the formatting at the cursor or in the selection.
Paragraph formatting
| Property | Type | Description |
|---|---|---|
HorizontalTextAlign |
TTMSFNCGraphicsTextAlign |
gtaLeading, gtaCenter, gtaTrailing, gtaJustify |
LineSpacing |
Single |
Line spacing multiplier |
RichEditor1.HorizontalTextAlign := gtaCenter;
Lists
// Toggle ordered (numbered) list
RichEditor1.OrderedList := True;
// Toggle unordered (bulleted) list
RichEditor1.UnorderedList := True;
Indentation
RichEditor1.Indent; // increase indent
RichEditor1.Outdent; // decrease indent
Undo and redo
if RichEditor1.CanUndo then RichEditor1.Undo;
if RichEditor1.CanRedo then RichEditor1.Redo;
Inserting text
// Insert at cursor position
RichEditor1.InsertText('Hello, world!');
Reading content
// Plain text
var plain := RichEditor1.PlainText;
// HTML
var html := RichEditor1.HTML;
Combining programmatic editing, formatting, and content retrieval
RichEditor1.SelectAll;
RichEditor1.Delete;
// Heading
RichEditor1.FontSize := 18;
RichEditor1.Bold := True;
RichEditor1.InsertText('Project Report');
RichEditor1.Bold := False;
RichEditor1.FontSize := 12;
RichEditor1.InsertLineBreak;
RichEditor1.InsertLineBreak;
// Paragraph
RichEditor1.HorizontalTextAlign := gtaLeading;
RichEditor1.InsertText(
'This report summarizes the work completed in Q2.');
RichEditor1.InsertLineBreak;
RichEditor1.InsertLineBreak;
// Bulleted list
RichEditor1.UnorderedList := True;
RichEditor1.InsertText('Feature A completed');
RichEditor1.InsertLineBreak;
RichEditor1.InsertText('Feature B in progress');
RichEditor1.InsertLineBreak;
RichEditor1.UnorderedList := False;
Related API
TTMSFNCRichEditor—Bold,Italic,Underline,FontName,FontSize,FontColor,InsertText,SelectAll,Undo,Redo
See also
- Images and links — embed images and insert hyperlinks
- Toolbar — connect the toolbar for interactive formatting