Look at the scroll bars:
ScrollBox1.VertScrollBar.Range ScrollBox1.HorzScrollBar.Range
It can be less than the height and width if the logical scroll area is not larger than the physical area (in this case, the scroll bars are not visible)
Or use this to get the maximum value of both:
var AHeight, AWidth: Integer; begin AHeight := Max(ScrollBox1.VertScrollBar.Range, ScrollBox1.Height); AWidth := Max(ScrollBox1.HorzScrollBar.Range, ScrollBox1.Width); ShowMessageFmt('%d,%d', [AHeight, AWidth]); end;
Edit From @Altar's comments, I can add a logical height and / or width is not a problem. If you want to add any control that occupies the entire height of the scrollbar, use AHeight from the calculation above, but set Top to a negative VertScrollBar.Position element, something like this:
procedure TForm2.Button3Click(Sender: TObject); var AHeight, AWidth: Integer; Btn: TButton; begin AHeight := Max(ScrollBox1.VertScrollBar.Range, Height); AWidth := Max(ScrollBox1.HorzScrollBar.Range, Width); Btn := TButton.Create(Self); Btn.Parent := ScrollBox1; Btn.Left := 15; Btn.Top := -ScrollBox1.VertScrollBar.Position; Btn.Height := AHeight; end;
source share