例:
if Pos('->>', DebugListBox.Items[index]) > 0 then
DebugListBox.Canvas.Font.Color := clRed ;
if Pos('<<', DebugListBox.Items[index]) > 0 then
DebugListBox.Canvas.Font.Color := clBlue
else if Pos('系统:', DebugListBox.Items[index]) > 0 then
DebugListBox.Canvas.Font.Color := clGreen;
其實Memo也是可以實現的,貼段代碼給你看看:
procedure TForm1.Button5Click(Sender: TObject);
var ec:tcanvas;
i,j:integer;
begin
try
Memo1.Lines.Add(edit1.Text+#13+#10+edit2.Text);
ec:=tcanvas.Create;
ec.Handle:=getdc(Memo1.Handle);
ec.Font.Color:=clred;
for i:=0 to Memo1.Lines.Count -1 do
begin
if i mod 2 = 0 then
ec.Font.Color := clBlue
else
ec.Font.Color := Clred;
ec.TextOut(1,i*13,Memo1.Lines[i]);
finally
ec.Free;
end;
end;
参考下面的代码:
FontDialog1.Font.Assign(Editor.SelAttributes);
if FontDialog1.Execute then
CurrText.Assign(FontDialog1.Font);
SelectionChange(Self);
Editor.SetFocus;