delphiscrollbardelphi-10.1-berlintscrollbox

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


Solution

  • 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;