How to detect if a TreeView has a scrollbar and how to change its position? (Views: 27)
Problem/Question/Abstract: How to detect if a TreeView has a scrollbar? How to change the scrollbar in a TreeView (if it has one)? Answer: procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); var iMin, iMax: Integer; bTreeViewVertScrollBarVisible: Boolean; begin bTreeViewVertScrollBarVisible := True; GetScrollRange(Form1.TreeView1.Handle, SB_VERT, iMin, iMax); if iMin = iMax then bTreeViewVertScrollBarVisible := False; // No scrollbar visible if bTreeViewVertScrollBarVisible then begin iPos := GetScrollPos(Form1.TreeView1.Handle, SB_VERT); SetScrollPos(Form1.TreeView1.Handle, SB_VERT, iPos + 1, True); // Don't set Handled to True! // If you do that then ONLY the scrollbar changes but NOT the // content of the TreeView! end; end; |