It draws line numbers in the editor itself, in OnPaint event.
But you can easily modify it to draw next to the editor.
This code supports text items placed on multiple lines (they are enumerated using ItemPart variable).
Code: Select all
procedure TForm3.RichViewEdit1Paint(Sender: TCustomRichView; ACanvas: TCanvas;
Prepaint: Boolean);
var
ItemNo, ItemPart, LineNo, TextHeight: Integer;
IsFromNewLine: Boolean;
R: TRect;
Pt: TPoint;
begin
if Prepaint then
exit;
ItemNo := Sender.FirstItemVisible;
if ItemNo < 0 then
exit;
ACanvas.Font.Name := 'Tahoma';
ACanvas.Font.Size := 8;
ACanvas.Font.Style := [];
ACanvas.Font.Color := clNavy;
ACanvas.Brush.Style := bsSolid;
ACanvas.Brush.Color := clWhite;
TextHeight := ACanvas.TextHeight('0');
SetTextAlign(ACanvas.Handle, TA_LEFT or TA_TOP);
LineNo := Sender.GetLineNo(ItemNo, Sender.GetOffsBeforeItem(ItemNo));
for ItemNo := ItemNo to Sender.LastItemVisible do
begin
ItemPart := 0;
IsFromNewLine := Sender.IsFromNewLine(ItemNo);
while Sender.GetItemCoordsEx(Sender.RVData, ItemNo, ItemPart, False, R) do
begin
if IsFromNewLine then
begin
Pt.X := 0;
Pt.Y := (R.Top + R.Bottom - TextHeight) div 2;
Pt := Sender.DocumentToClient(Pt);
ACanvas.TextOut(Pt.X, Pt.Y, IntToStr(LineNo));
inc(LineNo);
end;
IsFromNewLine := True;
inc(ItemPart);
end;
end;
end;