Recent

Author Topic: [Resolved] TTreeView Changing Arrow based on Selection Status  (Read 1593 times)

daz

  • Full Member
  • ***
  • Posts: 112
    • http://matt-shaffer.com
[Resolved] TTreeView Changing Arrow based on Selection Status
« on: November 25, 2018, 09:59:39 pm »
I am doing a lot of color customization / butchering with TTreeView  :P

One of things I have done is changed the selection color and enabled RowSelect

OnCustomDrawArrow works great, except I don't think there's a way to tell if the current item the arrow being drawn for is a selected item or not.

For example, see my attached screenshots.

I would like that if I am drawing the arrow for the currently selected node, I would draw the arrow in a different color (black).

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.tvNotebookCustomDrawArrow(Sender: TCustomTreeView;
  2.   const ARect: TRect; ACollapsed: Boolean);
  3. var
  4.   points: array of TPoint;
  5. begin
  6.   Sender.Canvas.Brush.Color := clBlack;
  7.   Sender.Canvas.FillRect(ARect);
  8.   Sender.Canvas.Pen.Width := 0;
  9.   Sender.Canvas.Pen.Color := clWhite;
  10.   Sender.Canvas.Brush.Color := clWhite;
  11.   if ACollapsed then begin
  12.     SetLength(points, 3);
  13.     points[0] := Point(ARect.Left, ARect.Top);
  14.     points[1] := Point(ARect.Left, ARect.Top + ARect.Height);
  15.     points[2] := Point(ARect.Left + ARect.Width, ARect.Top + ARect.Height div 2);
  16.     Sender.Canvas.Polygon(points);
  17.   end else begin
  18.     SetLength(points, 3);
  19.     points[0] := Point(ARect.Left, ARect.Top);
  20.     points[1] := Point(ARect.Left + ARect.Width, ARect.Top);
  21.     points[2] := Point(ARect.Left + ARect.Width div 2, ARect.Top + ARect.Height);
  22.     Sender.Canvas.Polygon(points);
  23.   end;
  24.   Sender.Canvas.Brush.Style := bsClear;
  25. end;  
  26.  
« Last Edit: November 25, 2018, 10:54:59 pm by daz »

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: TTreeView Changing Arrow based on Selection Status
« Reply #1 on: November 25, 2018, 10:32:15 pm »
Use the method GetNodeAt(X,Y) to determine the node from the rectangle passed as a parameter:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.TreeView1CustomDrawArrow(Sender: TCustomTreeView;
  2.   const ARect: TRect; ACollapsed: Boolean);
  3. var
  4.   node: TTreeNode;
  5. begin
  6.   node := Sender.GetNodeAt(ARect.Left+1, ARect.Top+1);
  7.   if node = Sender.Selected then begin  
  8.     // this is for selected node
  9.   end else
  10.     // this is for normal node
  11. end;

daz

  • Full Member
  • ***
  • Posts: 112
    • http://matt-shaffer.com
Re: TTreeView Changing Arrow based on Selection Status
« Reply #2 on: November 25, 2018, 10:54:48 pm »
This works perfect, thanks a bunch!

 

TinyPortal © 2005-2018