这类问题不是这些高手关注的方向,其实只要多用心看看、写写代码,这类问题其实很easy:
form.create中写(TV为TTreeView):
Randomize;
SetBkMode(TV.Canvas.Handle, TRANSPARENT);
然后:
procedure TFrm_Tree.TVAdvancedCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
var PaintImages, DefaultDraw: Boolean);
var
i, w: integer;
NodeRect: TRect;
r, g, b: byte;
ws: widestring;
begin
if Stage <> cdPostPaint then exit;
with Sender.Canvas do
begin
NodeRect := Node.DisplayRect(True);
ws := Node.Text;
w := NodeRect.left + 2 - TextWidth(copy(ws, 1, 1));
for i := 1 to length(ws) do
begin
r := Random(256);
g := Random(256);
b := Random(256);
SetTextColor(Handle, rgb(r, g, b));
w := w + TextWidth(copy(ws, i - 1, 1));
TextOut(w, NodeRect.Top + 1, copy(ws, i, 1));
end;
end;
end;