Formatted Text and Links
TTMSFNCHTMLText renders short pieces of formatted text inside forms, dashboards, dialogs, and other compact UI surfaces. Use it when a label needs inline emphasis, color, line breaks, images, or clickable anchors while still behaving like a normal control.
Basic Formatted Text
Set Text to the content to render. Keep DisplayHTML enabled for markup, then use WordWrapping, HorizontalTextAlign, VerticalTextAlign, and the Font object to tune the layout.
procedure TForm1.ConfigureHTMLText;
begin
TMSFNCHTMLText1.Text := '<b>Status</b><br><font color="#1BADF8">Connected</font>';
TMSFNCHTMLText1.DisplayHTML := True;
TMSFNCHTMLText1.WordWrapping := True;
TMSFNCHTMLText1.HorizontalTextAlign := gtaLeading;
TMSFNCHTMLText1.VerticalTextAlign := gtaCenter;
end;
Use AutoSize, AutoWidth, and AutoHeight when the control should resize to its content. Keep a fixed size when the surrounding layout should remain stable.
Inline Images
Assign a BitmapContainer before using image references in the text. This keeps icons shared and themeable across controls instead of embedding separate image instances in each label.
procedure TForm1.ConfigureHTMLTextImages;
begin
TMSFNCHTMLText1.BitmapContainer := TMSFNCBitmapContainer1;
TMSFNCHTMLText1.Text := '<img src="info"> <b>Profile complete</b>';
TMSFNCHTMLText1.WordWrapping := True;
end;
Clickable Anchors
Anchors can open automatically through AutoOpenURL, or you can handle OnAnchorClick when the application needs to route the click internally.
procedure TForm1.ConfigureHTMLTextAnchor;
begin
TMSFNCHTMLText1.Text := 'Open the <a href="settings">settings</a> page.';
TMSFNCHTMLText1.AutoOpenURL := False;
TMSFNCHTMLText1.OnAnchorClick := TMSFNCHTMLText1AnchorClick;
end;
procedure TForm1.TMSFNCHTMLText1AnchorClick(Sender: TObject; AAnchor: string);
begin
if AAnchor = 'settings' then
ShowMessage('Open settings.');
end;
Combining formatted text, inline images, and anchor handling
The following example displays a notification label with a status icon, a bolded title, a description line, and a clickable "Details" link:
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCHTMLText1.BitmapContainer := BitmapContainer1;
TMSFNCHTMLText1.WordWrapping := True;
TMSFNCHTMLText1.AutoHeight := True;
TMSFNCHTMLText1.Text :=
'<img src="warning"/> ' +
'<b>Disk space low</b><br>' +
'Only 2 GB remaining on drive C:<br>' +
'<a href="details">Show details...</a>';
end;
procedure TForm1.TMSFNCHTMLText1AnchorClick(Sender: TObject; AAnchor: string);
begin
if AAnchor = 'details' then
ShowDiskSpaceDialog;
end;
Layout Checklist
Use TextIndentMargins when text needs padding away from the border, and adjust Trimming when a fixed-width label must avoid overflow. If a label contains both links and inline images, test it at the narrowest expected width so wrapping remains readable.