- Em Uses adicione; UxTheme
- Em um Form coloque um componente TreeView
- No evento OnCreate do Form, coloque o código para popular o TreeView;
function CriaValor: string;
begin
Randomize;
Result:= IntToStr(Random(MaxInt))+' - '+IntToStr(Random(MaxInt))+' - '+IntToStr(Random(MaxInt))+' - '+IntToStr(Random(MaxInt));
end;
var
node: array[0..2] of TTreeNode;
nodeFilho: array[0..2] of TTreeNode;
i, j: integer;
begin
for I := Low(node) to High(node) do
begin
node[i]:= tv1.Items.Add(nil, CriaValor);
for j := 0 to 10 do
begin
tv1.Items.AddChild(node[i], CriaValor);
end;
end;
tv1.FullExpand;
- No evento OnAdvancedCustomDrawItem adicione:
function Tab(p_value: Integer): string;
var
i: Integer;
begin
for I := 0 to p_value do
Result:= Result + ' ';
end;
var
wl_NodeRect: TRect;
wl_NodeTextRect: TRect;
wl_Text: string;
wl_ThemeData: HTHEME;
wl_TreeItemState: Integer;
begin
if Stage = cdPrePaint then
begin
wl_NodeRect := Node.DisplayRect(False);
wl_NodeTextRect := Node.DisplayRect(True);
if (cdsSelected in State) and Sender.Focused then
wl_TreeItemState := TREIS_SELECTED
else
if (cdsSelected in State) and (cdsHot in State) then
wl_TreeItemState := TREIS_HOTSELECTED
else
if cdsSelected in State then
wl_TreeItemState := TREIS_SELECTEDNOTFOCUS
else
if cdsHot in State then
wl_TreeItemState := TREIS_HOT
else
wl_TreeItemState := TREEITEMStateFiller0;
if wl_TreeItemState <> TREEITEMStateFiller0 then
begin
wl_ThemeData := OpenThemeData(Sender.Handle, VSCLASS_TREEVIEW);
DrawThemeBackground(wl_ThemeData, Sender.Canvas.Handle, TVP_TREEITEM, wl_TreeItemState,
wl_NodeRect, nil);
CloseThemeData(wl_ThemeData);
end;
SetBkMode(Sender.Canvas.Handle, TRANSPARENT);
SetTextColor(Sender.Canvas.Handle, clBlack);
wl_Text := Tab(10)+Node.Text;
wl_NodeTextRect.Right:= tv1.Width;
Sender.Canvas.TextRect(wl_NodeTextRect, wl_Text,
[tfVerticalCenter, tfSingleLine, tfEndEllipsis, tfLeft]);
wl_Text:= 'Linha '+IntToStr(Node.AbsoluteIndex + 1);
SetBkMode(Sender.Canvas.Handle, OPAQUE);
SetTextColor(Sender.Canvas.Handle, $008AC5FF);
Sender.Canvas.TextRect(wl_NodeRect, wl_Text,
[tfVerticalCenter, tfSingleLine, tfEndEllipsis, tfLeft]);
end;
PaintImages := False;
DefaultDraw := False;
end;
Atenciosamente: Jucélio Moura.