实现鼠标右键选中结点
1. 设置treeview的属性RightClickSelect为True
2. 编写一个函数
procedure ChangeSelectNode(tree:TTreeView;x,y:integer;Button: TMouseButton);
var
anode:TTreeNode;
begin
if button=mbright then {是否按了右键}
begin
anode:=tree.GetNodeAt(x,y); {取x,y坐标下的结点}
if anode<>nil then
anode.Selected :=true; {设置点中结点为选中}
end;
end;
3. 在treeview的OnMouseDown事件加入下面的语句
changeselectnode(treeview1,x,y,button);
******************************
procedure TForm1 . TreeView1ContextPopup ( Sender : TObject ; MousePos : TPoint ;
var Handled : Boolean );
var
tmpNode : TTreeNode ;
begin
tmpNode := ( Sender as TTreeView ). GetNodeAt ( MousePos . X , MousePos . Y );
if tmpNode <> nil then
TTreeView ( Sender ). Selected := tmpNode ;
end ;