Author: Maarten de Haan
How to detect if a TreeView has a scrollbar?
How to change the scrollbar in a TreeView (if it has one)?
Answer:
1 2 procedure TForm1.FormMouseWheelDown(Sender: TObject;
3 Shift: TShiftState;
4 MousePos: TPoint;
5 var Handled: Boolean);
6 7 var8 iMin, iMax: Integer;
9 bTreeViewVertScrollBarVisible: Boolean;
10 11 begin12 bTreeViewVertScrollBarVisible := True;
13 GetScrollRange(Form1.TreeView1.Handle, SB_VERT, iMin, iMax);
14 if iMin = iMax then15 bTreeViewVertScrollBarVisible := False; // No scrollbar visible16 17 if bTreeViewVertScrollBarVisible then18 begin19 iPos := GetScrollPos(Form1.TreeView1.Handle, SB_VERT);
20 SetScrollPos(Form1.TreeView1.Handle, SB_VERT, iPos + 1, True);
21 // Don't set Handled to True!22 // If you do that then ONLY the scrollbar changes but NOT the23 // content of the TreeView!24 end;
25 26 end;