首页 > Windows开发 > 详细

[DELPHI]TreeView精确定位到每一个ITEM

时间:2020-06-29 22:01:02      阅读:93      评论:0      收藏:0      [点我收藏+]
procedure TForm1.TreeView1Click(Sender: TObject); 
var 
  aPoint: TPoint; 
  aNode: TTreeNode; 
  aHitTest: THitTests; 
begin 
  if GetCursorPos(aPoint) then 
  begin 
    aPoint := TreeView1.ScreenToClient(aPoint); 
    aHitTest := TreeView1.GetHitTestInfoAt(aPoint.X, aPoint.Y);

    //htOnItem, htOnButton, htOnIcon, htOnIndent, htOnLabel 
    if not ((htOnItem in aHitTest)or (htOnLabel in aHitTest)) then  Exit;

    aNode := TreeView1.GetNodeAt(aPoint.X, aPoint.Y); 
    if not Assigned(aNode) then  Exit;

    //test: Caption := aNode.Text; 
    //do your code 
  end; 
end;

procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton; 
  Shift: TShiftState; X, Y: Integer); 
var 
  aNode: TTreeNode; 
begin 
  aNode := TreeView1.GetNodeAt(X, Y); 
  if not Assigned(aNode) then  Exit;

  //do your code 
end;

 

[DELPHI]TreeView精确定位到每一个ITEM

原文:https://www.cnblogs.com/jijm123/p/13210486.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!