function TForm1.SelectLine(Memo:TRichEdit; L: integer;BgrColor,TxtColor: TColor): integer;
var Text :
array [0..4095]
of char;
s :
string;
R : TRect;
hMemo : THandle;
WLine, HLine : integer;
tm : TTEXTMETRIC;
begin
hMemo := Memo.Handle;
Word((@Text)^) := SizeOf(Text);
SetString(s,Text,SendMessage(hMemo,EM_GETLINE,L,Longint(@Text)));
SendMessage(hMemo,EM_GETRECT,0,Longint(@R));
WLine := R.Right-R.Left+1;
with TControlCanvas.Create
do
try
Control := Memo;
Font := Memo.Font;
GetTextMetrics(
Handle,tm);
HLine := tm.tmHeight + tm.tmExternalLeading;
Brush.Color := BgrColor;
FillRect(Rect(0,L*HLine,WLine+1,(L+1)*HLine+1));
SetBkMode(
Handle,TRANSPARENT);
SetTextColor(
Handle,TxtColor);
TextOut(1,L*HLine+1,s);
finally
Free;
end;
end;
function TForm1.UnselectLine(Memo:TRichEdit; L:integer):integer;
var
Text:
array [0..4095]
of char;
s:
string;
R:TRect;
hMemo:THandle;
WLine,HLine:integer;
tm:TTEXTMETRIC;
begin
hMemo:=Memo.Handle;
Word((@Text)^) := SizeOf(Text);
SetString(s, Text, SendMessage(hMemo, EM_GETLINE, L,Longint(@Text)));
SendMessage(hMemo,EM_GETRECT,0,Longint(@R));
WLine:=R.Right-R.Left+1;
with TControlCanvas.Create
do
try
Control := Memo;
Font := Memo.Font;
GetTextMetrics (
Handle, tm);
HLine := tm.tmHeight + tm.tmExternalLeading;
Brush.Color:=Memo.Color;
FillRect(Rect(0,L*HLine,WLine+1,(L+1)*HLine+1));
SetBkMode(
Handle,TRANSPARENT);
SetTextColor(
Handle,Font.Color);
TextOut(1,L*HLine+1,s);
finally
Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SelectLine(RichEdit1,1,clNavy,clWhite);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
UnselectLine(RichEdit1,1);
end;