检测Delphi FMX列表框何时滚动到底部?

检测Delphi FMX列表框何时滚动到底部?,delphi,listbox,firemonkey,Delphi,Listbox,Firemonkey,我需要检测用户何时在列表框中向下滚动到底部,这样我就可以获取列表框中接下来要显示的25个项目,有什么提示吗?好的,让我们来分析一下,首先我们进入FMX.ListBox单元 procedure TCustomListBox.ScrollToItem(const Item: TListBoxItem); begin if (Item <> nil) and (Content <> nil) and (ContentLayout <> nil) then b

我需要检测用户何时在列表框中向下滚动到底部,这样我就可以获取列表框中接下来要显示的25个项目,有什么提示吗?

好的,让我们来分析一下,首先我们进入FMX.ListBox单元

procedure TCustomListBox.ScrollToItem(const Item: TListBoxItem);
begin
  if (Item <> nil) and (Content <> nil) and (ContentLayout <> nil) then
  begin
    if VScrollBar <> nil then
    begin
      if Content.Position.Y + Item.Position.Y + Item.Margins.Top + Item.Margins.Bottom + Item.Height >
        ContentLayout.Position.Y + ContentLayout.Height then
        VScrollBar.Value := VScrollBar.Value + (Content.Position.Y + Item.Position.Y + Item.Margins.Top +
          Item.Margins.Bottom + Item.Height - ContentLayout.Position.Y - ContentLayout.Height);
      if Content.Position.Y + Item.Position.Y < ContentLayout.Position.Y then
        VScrollBar.Value := VScrollBar.Value + Content.Position.Y + Item.Position.Y - ContentLayout.Position.Y;
    end;
    if HScrollBar <> nil then
    begin
      if Content.Position.X + Item.Position.X + Item.Margins.Left + Item.Margins.Right + Item.Width >
        ContentLayout.Position.X + ContentLayout.Width then
        HScrollBar.Value := HScrollBar.Value + (Content.Position.X + Item.Position.X + Item.Margins.Left +
          Item.Margins.Right + Item.Width - ContentLayout.Position.X - ContentLayout.Width);
      if Content.Position.X + Item.Position.X < 0 then
        HScrollBar.Value := HScrollBar.Value + Content.Position.X + Item.Position.X - ContentLayout.Position.X;
    end;
  end;
end;
将其添加到列表框所在的表单中,然后使用
VScrollChange(发送方:TObject)事件并对if条件进行反向工程

像这样的东西对你有用

procedure TForm1.ListBox1VScrollChange(Sender: TObject);
var
  S:single;
begin
  S:= ListBox1.ContentRect.Height;

  if ListBox1.VScrollBar.ValueRange.Max = S + ListBox1.VScrollBar.Value then
    Caption := 'hit'
  else
    Caption := 'no hit';
end;

当试图解决这些类型的问题时,请始终寻找ScrollToControl函数并从中获得灵感。上面的代码处理添加到滚动框中的简单项目。如果你在边距或填充物方面有任何问题,只需改进公式即可

你看到这个了吗?我认为这是相同的想法。ListBox和ListView有不同的属性、选项,ListBox没有这些选项…我还没有检查列表框,但是如果它有scrolltoControl(),那么你需要的就是它。scrolltoControl()?,嗯,你的想法是什么?太棒了,但我注意到了一些东西,当你用鼠标滚动它不工作…我只是尝试了一下,你是对的。显然,使用鼠标滚轮时不会调用
VScrollChange
。但是您可以将
mouseweel
事件与相同的代码一起使用,它将正常工作。
procedure TForm1.ListBox1VScrollChange(Sender: TObject);
var
  S:single;
begin
  S:= ListBox1.ContentRect.Height;

  if ListBox1.VScrollBar.ValueRange.Max = S + ListBox1.VScrollBar.Value then
    Caption := 'hit'
  else
    Caption := 'no hit';
end;