Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect whether scrollbar is at the very bottom?

It is easy to detect whether the vertical scrollbar of a TScrollBox is at the very top or not:

IsScrollBarAtTop := ScrollBox1.VertScrollBar.Position = 0;

enter image description here

But how can I detect whether the vertical scrollbar of a TScrollBox is at the very BOTTOM or not?

enter image description here

like image 356
user1580348 Avatar asked Dec 05 '16 09:12

user1580348


2 Answers

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;
like image 58
Sertac Akyuz Avatar answered Oct 05 '22 12:10

Sertac Akyuz


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.

like image 38
LU RD Avatar answered Oct 05 '22 11:10

LU RD