procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var TVNODE:TTreeNode;
bdwidth:integer; //边界的宽度
begin
bdwidth:=10;
TVNODE:=TreeView1.GetNodeAt(X,Y);
if TVNODE<>nil then
if y>TreeView1.ClientRect.Bottom-bdwidth then
TreeView1.Selected:=TVNODE.GetNext;
if y<TreeView1.ClientRect.Top+bdwidth then
TreeView1.Selected:=TVNODE.GetPrev;
end;
to menxin:
用TreeView1.Selected:=TVNODE.GetNext好像有一个问题,就是:
当需要在OnDragDrop中区分节点Selected和GetNodeAt(x,y)时,
当滚动条移动后,这句话会导致这两个节点实际上成为一个节点。
可以考虑改为:
if (NODE<>nil) then begin
if y>TreeView1.ClientRect.Bottom-bdWidth then
if (Node.GetNext)<>nil then
(NODE.GetNext).MakeVisible;
if y<TreeView1.ClientRect.Top+bdwidth then
if (Node.GetPrev)<>nil then
(NODE.GetPrev).MakeVisible;
end;