procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
NodeRect: TRect;
begin
//If DefaultDraw it is true, any of the node's font properties can be
//changed. Note also that when DefaultDraw = True, Windows draws the
//buttons and ignores our font background colors, using instead the
//TreeView's Color property.
//if cdsSelected in State then
//begin
// Sender.Canvas.Font.Assign(Form1.Font);
// Sender.Canvas.Brush.Color := clBlue;
//end;
DefaultDraw := False;
//DefaultDraw = False means you have to handle all the item drawing yourself,
//including the buttons, lines, images, and text.
if not DefaultDraw then
begin
//draw the selection rect.
if cdsSelected in State then
begin
NodeRect := Node.DisplayRect(True);
Sender.Canvas.FillRect(NodeRect);
end;
NodeRect := Node.DisplayRect(False);
Sender.Canvas.Brush.Color := clWindow;
Sender.Canvas.Brush.Style := bsSolid;
Sender.Canvas.FillRect(NodeRect);
NodeRect.Left := NodeRect.Left + (Node.Level * TreeView1.Indent);
//NodeRect.Left now represents the left-most portion of the expand button
DrawButton(NodeRect, Node);
NodeRect.Left := NodeRect.Left + TreeView1.Indent + FButtonSize;
//NodeRect.Left is now the leftmost portion of the image.
DrawImage(NodeRect, Node.ImageIndex);
NodeRect.Left := NodeRect.Left + ImageList1.Width;
//Now we are finally in a position to draw the text.
Sender.Canvas.TextOut(NodeRect.Left, NodeRect.Top, Node.Text);
Sender.Canvas.Font.Style := [fsItalic, fsBold];
Sender.Canvas.TextOut(NodeRect.Left + Sender.Canvas.TextWidth(Node.Text), NodeRect.Top, 'asd');
end;
end;