Hit Test TTreview más / menos (contraer / expandir) ícono - Delphi

I am using a TTreeview component in Delphi and I have customized the drag and drop functions. I start the drag on the mouse down (since it is a custom behavior), but I don't want to start the drag event when the user click on the +/- or expand and collapse icons.

Is there a way to know if the user has clicked on the caption of the node or on the expand/collapse icon?


preguntado el 09 de marzo de 12 a las 15:03

1 Respuestas

El TTreeView component includes the GetHitTestInfoAt método para este propósito.

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 ......

La lista completa de posibles miembros de los THitTests el conjunto es:

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

respondido 09 mar '12, 16:03

How can i select the treenode if i click only on the expand/collapse icon? Thank You. - john_who_is_doe

@tdiop detect the appropiate htXXX. The users won't thank you though. - David Heffernan

Ok, htOnButton and TreeView1.GetNodeAt(X, Y) did the trick. (: - john_who_is_doe

@tdiop your users will still hate losing their selection though! - David Heffernan

what do you mean by that? Node := tw.GetNodeAt(X, Y), then node.selected := true; - john_who_is_doe

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.