* * *

Author Topic: TreeView patch to add hottrack via item background color  (Read 236 times)

Alextp

  • Hero Member
  • *****
  • Posts: 629
    • UVviewsoft
TreeView patch to add hottrack via item background color
« on: May 31, 2018, 02:47:08 pm »
i want to make such patch for Treeview.
it is like VSCode editor does when mouse moves over tree.
a- will be it be used?
b- what new property to you recommend to add it?

wp

  • Hero Member
  • *****
  • Posts: 4602
Re: TreeView patch to add hottrack via item background color
« Reply #1 on: May 31, 2018, 03:39:20 pm »
I don't think that it is a good idea to blow up standard controls with more and more user-provided properties, in particular since the TreeView already has ample custom drawing capabilities. After a few minutes of navigating through the treeview code I was able to accomplish your requirement by this OnCustomDraw event handler:
Code: Pascal  [Select]
  1. procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
  2.   Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
  3. var
  4.   R: TRect;
  5. begin
  6.   R := Node.DisplayRect(true);
  7.   if PtInRect(R, sender.ScreenToClient(Mouse.CursorPos)) then begin
  8.     Sender.Canvas.Brush.Color := clYellow;
  9.     Sender.Canvas.FillRect(R);
  10.   end;
  11.   inherited;
  12. end;
« Last Edit: May 31, 2018, 04:07:13 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Alextp

  • Hero Member
  • *****
  • Posts: 629
    • UVviewsoft
Re: TreeView patch to add hottrack via item background color
« Reply #2 on: May 31, 2018, 06:11:01 pm »
adding all props to LCL isnot good, but maybe patch will be faster, smaller than this.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus