2005. január 13., csütörtök

Implement drag scrolling in a TTreeView


Problem/Question/Abstract:

Can someone tell me where I can look to get some help implementing scrolling while a drag operation is in effect.

Answer:

procedure TfrmajNewsEditor.ajNewsTreeViewDragOver(Sender, Source: TObject;
  X, Y: Integer; State: TDragState; var Accept: boolean);
const
  cScrollOffset = 5;
var
  Node: TTreeNode;
begin
  Accept := true; {Always accept}
  Node := fajNewsTreeView.TopItem; {Get the top node as a reference}
  if (y < cScrollOffset) then {Are we dragging at the top of the treeview?}
    SendMessage(fajNewsTreeView.Handle, WM_VSCROLL, SB_LINEUP, 0)
      {We'll scroll the treeview}
  else if (y > fajNewsTreeView.Height - cScrollOffset) then {Dragging at the bottom?}
    SendMessage(fajNewsTreeView.Handle, WM_VSCROLL, SB_LINEDOWN, 0); {Do a scroll}
  if (Node <> fajNewsTreeView.TopItem) then {Did we scroll? We'll need to redraw.}
    fajNewsTreeView.Refresh; {The treeview gets in a mess if we don't.}
end;

Nincsenek megjegyzések:

Megjegyzés küldése