whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

86 Visitors Online


 
...scroll a Treeview when Drag/Drop?
Autor: Damian Gorski
[ Print tip ]  

Tip Rating (9):  
     


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;

{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
             ERWEITERUNG von / ENHANCEMENT sent by
           Stef Mientki (http://Punthoofd.flappie.nl)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}

{
Thomas Stutz wrote a code snippet, to scroll a treeview,
when dragging near top/bottom of a treeview.
But with his code, you had to keep your mouse moving.
Adding a timer, does the work for you.
}
....
  private
    
{ Private declarations }
    
scroll_down   :boolean;
....

procedure TForm_test_list.tv_filesDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
(*******************************************************************************
Start auto scroll when draging near top or bottom
*******************************************************************************)
begin
  if 
y<15 then
  begin
    
scroll_down:=true;
    timer_autoscroll.Enabled:=true;
  end
  else
    if 
(list.Height-y)<15 then
    begin
      
scroll_down:=false;
      timer_autoscroll.Enabled:=true;
    end
    else 
timer_autoscroll.Enabled:=false;
end;

procedure TForm_test_list.Timer_autoscrollTimer(Sender: TObject);
(*******************************************************************************
Set timer to about 100 msec (disabled at initialization)
*******************************************************************************)
begin
  if 
scroll_down then
    
SendMessage(tv_files.Handle, WM_VSCROLL, SB_LINEUP, 0)
  else
    
SendMessage(tv_files.Handle, WM_VSCROLL, SB_LINEDOWN, 0);
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners