It is easy to detect whether the vertical scrollbar of a TScrollBox
is at the very top or not:
IsScrollBarAtTop := ScrollBox1.VertScrollBar.Position = 0;
But how can I detect whether the vertical scrollbar of a TScrollBox
is at the very BOTTOM or not?
You can retrieve scroll bar information through the API and determine if its at the bottom.
function IsScrollBarAtBottom(Box: TScrollBox): Boolean;
var
Info: TScrollInfo;
begin
Info.cbSize := SizeOf(Info);
Info.fMask := SIF_POS or SIF_RANGE or SIF_PAGE;
Win32Check(GetScrollInfo(Box.Handle, SB_VERT, Info));
Result := Info.nPos >= Info.nMax - Info.nMin - Info.nPage;
end;
From Vcl.Forms.TControlScrollBar.Range:
Range represents the virtual size (in pixels) of the associated control's client area. For example, if the Range of a form's horizontal scroll bar is set to 500, and the width of the form is 200, the scroll bar's Position can vary from 0 to 300.
IsScrollBarAtBottom := ScrollBox1.VertScrollBar.Position =
(ScrollBox1.VertScrollBar.Range - ScrollBox1.ClientHeight);
If the range is less than the height of the scrollbox, the scrollbar is not visible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With