在拖拉Treeview里的信息时,如何让Treeview的滚动条跟着鼠标拖动的方向一起滚动?
就像msn里中拖动一个好友,往下拖时,Treeview的滚动条就跟着往下。
帮你顶
在 TTreeView 的 OnMouseDown 事件中加入一下代码
if Y > TreeView1.Height - 10 then
PostMessage(TreeView1.Handle, WM_VSCROLL, SB_LINEDOWN, 0)
else if Y < 10 then
PostMessage(TreeView1.Handle, WM_VSCROLL, SB_LINEUP, 0)
procedure TForm1.TreeView1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Y>tempY then PostMessage(TreeView1.Handle, WM_VSCROLL, SB_LINEDOWN, 0)
else PostMessage(TreeView1.Handle, WM_VSCROLL, SB_LINEUP, 0);
tempY:=Y;
end;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if (y < 15) then {On the upper edge - should scroll up }
SendMessage(TreeView1.Handle, WM_VSCROLL, SB_LINEUP, 0)
else if (TreeView1.Height - y < 15) then { On the lower edge - should scroll down }
SendMessage(TreeView1.Handle, WM_VSCROLL, SB_LINEDOWN, 0);
end;