Recent

Author Topic: [SOLVED]How to change the color of the node branches of TreeView  (Read 2919 times)

tomitomy

  • Sr. Member
  • ****
  • Posts: 251
Hi, I want to change the color of the node branches of TreeView, I don't know how to achieve, can someone help me?
« Last Edit: October 21, 2017, 03:01:30 pm by tomitomy »

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: How to change the color of the node branches of TreeView
« Reply #1 on: October 19, 2017, 03:38:00 pm »
Write a handler for the OnCustomDrawArrow event of the tree. Something like this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.TreeView1CustomDrawArrow(Sender: TCustomTreeView;
  2.   const ARect: TRect; ACollapsed: Boolean);
  3. begin
  4.   Sender.Canvas.Brush.Color := clSilver;
  5.   Sender.Canvas.FillRect(ARect);
  6.   if ACollapsed then begin
  7.     Sender.Canvas.Font.Color := clRed;
  8.     Sender.Canvas.TextOut(
  9.       ARect.Left + (ARect.Width - Sender.Canvas.TextWidth('+')) div 2,
  10.       ARect.Top + (ARect.Height - Sender.Canvas.TextHeight('+')) div 2,
  11.       '+');
  12.   end else begin
  13.     Sender.Canvas.Font.Color := clGreen;
  14.     Sender.Canvas.TextOut(
  15.       ARect.Left + (ARect.Width - Sender.Canvas.TextWidth('-')) div 2,
  16.       ARect.Top + (ARect.Height - Sender.Canvas.TextHeight('-')) div 2,
  17.       '-');
  18.   end;
  19.   Sender.Canvas.Brush.Style := bsClear;
  20.   Sender.Canvas.Pen.Color := clGray;
  21.   Sender.Canvas.Rectangle(ARect);
  22. end;

tomitomy

  • Sr. Member
  • ****
  • Posts: 251
Re: How to change the color of the node branches of TreeView
« Reply #2 on: October 19, 2017, 06:14:30 pm »
Thank you, @wp, you helped me, I know what to do next, thank you very much! :)

 

TinyPortal © 2005-2018