2009. december 18., péntek

How to scroll a TTreeView?


Problem/Question/Abstract:

How to scroll a TTreeView?

Answer:

procedure TForm1.FormMouseWheelUp(Sender: TObject;
  Shift: TShiftState;
  MousePos: TPoint;
  var Handled: Boolean);

var
  iPos: Integer;

begin
  iPos := GetScrollPos(Form1.TreeView1.Handle, SB_VERT);
  SetScrollPos(Form1.TreeView1.Handle, SB_VERT, iPos - 1, True);
  // Don't set Handled to True otherwise the scrollbar scrolls
  // but the content of the TreeView does NOT scroll!
  // I have not found a way to check if the TreeView has a scrollbar or not.
  // Maybe if you first call:
  // GetScrollRange(Form1.TreeView1.Handle, SB_VERT,lpMinPos,lpMaxPos);
  // and then:
  // if MaxPos = 0 and MinPos = 0 then there is no vertical scrollbar
  // if MaxPos <> 0 then there is a vertical scrollbar
end;

Nincsenek megjegyzések:

Megjegyzés küldése