Просто создайте собственный TxxxMemo: наследуйтесь от стандартного TMemo и перекройте метод Paint.
Вот мой старый пример, изменяющий цвет каждой строки:
unit Todrmemo;interfaceusesSysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls; typeTOwnerDrawMemo = class(TMemo)private{ Private declarations }procedure WMPaint(var Message: TWMPaint); message WM_PAINT;protected{ Protected declarations }public{ Public declarations }published{ Published declarations }end; procedure Register; implementation procedure TOwnerDrawMemo.WMPaint(var Message: TWMPaint);var Buffer: Array[0..255] of Char;PS: TPaintStruct;DC: HDC;i: Integer;X,Y,Z: Word;OldColor: LongInt;beginDC := Message.DC;if DC = 0 then DC := BeginPaint(Handle, PS);tryX := 1;Y := 1;SetBkColor(DC, Color);SetBkMode(DC, Transparent);OldColor := Font.Color;for i:=0 to Pred(Lines.Count) dobeginif odd(i) then SetTextColor(DC, clRed)else SetTextColor(DC, OldColor);Z := Length(Lines[i]);StrPCopy(Buffer, Lines[i]);Buffer[Z] := #0; { реально не нужно }TextOut(DC, X,Y, Buffer, Z);Inc(Y, abs(Font.Height));end;finallyif Message.DC = 0 then EndPaint(Handle, PS);end;end; procedure Register;beginRegisterComponents('Dr.Bob', [TOwnerDrawMemo]);end; end. |
Dr. Bob (drbob@pi.net) [000683]