Assign this code to TSRichViewEdit's OnPaintPage event.
The code draws line numbers at the left margin.
Numbering is restarted on each page.
Code: Select all
procedure TForm1.SRichViewEdit1PaintPage(Sender: TObject; PageNo: Integer;
PageRect, R: TRect; Canvas: TCanvas; Prepaint, Printing: Boolean);
const
PageNumberDX = 5; // distance between line numbers and text
var
i: Integer;
FirstItemNo, LastItemNo, Offs, ItemPart: Integer;
FirstPageNo, LastPageNo : Integer;
ItemRect: TRect;
srv: TSRichViewEdit;
TextHeight, LineNumber, Left, Top, LeftMargin: Integer;
begin
// line number font
Canvas.Font.Name := 'Tahoma';
Canvas.Font.Size := 6;
Canvas.Font.Style := [];
Canvas.Font.Color := clBtnShadow;
Canvas.Brush.Style := bsClear;
TextHeight := Canvas.TextHeight('0');
srv := Sender as TSRichViewEdit;
srv.GetPageStartItemNo(PageNo, FirstItemNo, Offs);
srv.GetPageLastItemNo(PageNo, LastItemNo, Offs);
LineNumber := 1;
LeftMargin := srv.GetLeftMargin100Pix(PageNo);
for i := FirstItemNo to LastItemNo do begin
if srv.RichViewEdit.GetItemStyle(i)=rvsTable then
continue;
ItemPart := 0;
while srv.GetItemBounds100(
srv.RichViewEdit.RVData, i, ItemRect,
FirstPageNo, LastPageNo, ItemPart) do begin
if (FirstPageNo = PageNo) and
((ItemPart>0) or srv.RichViewEdit.IsFromNewLine(i)) then begin
Left := PageRect.Left + LeftMargin - PageNumberDX -
Canvas.TextWidth(IntToStr(LineNumber));
Top := PageRect.Top + (ItemRect.Top+ItemRect.Bottom - TextHeight) div 2;
Canvas.TextOut(Left, Top, IntToStr(LineNumber));
inc(LineNumber);
end;
inc(ItemPart);
end;
end;
end;