Table of Contents

Horizontal ruler

TTMSFNCRichEditorHorizontalRuler adds document-style page margins, paragraph indents, and tab stops to a bound rich editor. Use it when the editor surface needs visible layout controls rather than property-only configuration. The ruler connects through the inherited RichEditor property, just like the edit and format toolbars.

Binding and placement

Bind the ruler to the same editor as the companion toolbars, then use Layout to decide where the ruler appears and which markers the user can adjust. AutoPosition and AutoWidth keep the ruler aligned with the editor content as the form changes size.

procedure TForm1.ConfigureRulerLayout;
begin
  with TMSFNCRichEditorHorizontalRuler1.Layout do
  begin
    // Place the ruler above the editor and let it track the editor width.
    RulerPosition := rpTop;
    AutoPosition  := True;   // keep the ruler aligned to the editor content
    AutoWidth     := True;   // match the ruler length to the editor

    // Hide markers you do not want the user to drag.
    ShowLeftMargin    := True;
    ShowRightMargin   := True;
    ShowLeftIndent    := True;
    ShowRightIndent   := True;
    ShowHangingIndent := False;

    // Tune the tick-mark scale and labeling.
    TickMarks.Step                := 5;
    TickMarks.LabelStep           := 10;
    TickMarks.ContinuousLabelSteps := False;
  end;
end;

Margins and paragraph indents

Page margins are configured on Layout, while paragraph indent markers are direct ruler properties. Set both before the user starts editing if the document should open with a known layout.

procedure TForm1.ConfigureRulerMarginsAndIndents;
begin
  TMSFNCRichEditorHorizontalRuler1.RichEditor := TMSFNCRichEditor1;

  // Page margins live on Layout and are expressed in ruler units.
  TMSFNCRichEditorHorizontalRuler1.Layout.LeftMargin  := 50;
  TMSFNCRichEditorHorizontalRuler1.Layout.RightMargin := 46;

  // Paragraph indents are properties of the ruler itself (also ruler units).
  TMSFNCRichEditorHorizontalRuler1.LeftIndent    := 10;  // left indent marker
  TMSFNCRichEditorHorizontalRuler1.RightIndent   := 8;   // right indent marker
  TMSFNCRichEditorHorizontalRuler1.HangingIndent := 4;   // first-line hanging box
end;

Tab stops and snapping

The Tabs collection stores the visible tab stops. Layout.TabMove controls how dragged stops snap, and Layout.TabSize sets the snapping distance when step snapping is enabled. Batch tab collection changes with BeginUpdate and EndUpdate to avoid repeated redraws.

procedure TForm1.ConfigureRulerTabs;
begin
  // TabMove controls how a dragged tab stop snaps: tmPixel (free), tmStep,
  // tmTickMark, tmLabel, or tmAll (snap to any of them).
  TMSFNCRichEditorHorizontalRuler1.Layout.TabMove := tmStep;
  TMSFNCRichEditorHorizontalRuler1.Layout.TabSize := 5;

  // Populate tab stops. AddTab takes the indent position in ruler units and
  // returns the index of the new stop. Batch the changes to redraw once.
  TMSFNCRichEditorHorizontalRuler1.Tabs.BeginUpdate;
  try
    TMSFNCRichEditorHorizontalRuler1.Tabs.Clear;
    TMSFNCRichEditorHorizontalRuler1.Tabs.AddTab(20);
    TMSFNCRichEditorHorizontalRuler1.Tabs.AddTab(40);
    TMSFNCRichEditorHorizontalRuler1.Tabs.AddTab(60);
  finally
    TMSFNCRichEditorHorizontalRuler1.Tabs.EndUpdate;
  end;
end;

Pitfalls

  • Bind the ruler before expecting live editor synchronisation. Without RichEditor, marker changes stay local to the ruler surface.
  • Choose the snap mode for the task. Free movement is useful for precision layout, while tick or step snapping is easier for form-like documents.

See also