Hit test TTreview plus / minus (collapse / expand) icon - Delphi

I am using a TTreeview component in Delphi and I have configured the drag and drop functionality. I start dragging down with the mouse (as this is normal behavior), but I don't want to fire a drag event when the user clicks on the +/- icons or expands and collapses.

Is there a way to tell if the user has clicked on the header node or the expand / collapse icon?



source to share

1 answer

The component TTreeView

includes GetHitTestInfoAt

for this purpose.

procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  HitTests: THitTests;
  HitTests := TreeView1.GetHitTestInfoAt(X, Y);
  if htOnButton in HitTests then
    //do something
  else if htOnLabel in HitTests then
    //do something else
  else if ......


A complete list of possible set members THitTests


  • htAbove
  • htBelow
  • htOnItem
  • htOnButton
  • htOnIcon
  • htOnIndent
  • htOnLabel
  • htOnRight
  • htOnStateIcon
  • htToLeft
  • htToRight


All Articles