1
votes

I want resize my form height by ListBox items count - increase height while scrollbar visible. How to know, is scrollbar visible or nor in TListbox? So, there are a tons of information for VCL (based on Handle) but not for FMX. Lazy method:

ListBox1.Items.Count * Round(ListBox1.ItemByIndex(0).Height)

This method not working properly because form border and caption can be different on different machines.

2

2 Answers

2
votes

To adjust form's height or width to accommodate some content you should use ClientWidth and ClientHeight properties of the form rather that Width and Height

ClientWidth and ClientHeight hold dimension of form without border, caption and menu area.

1
votes

If the parent control's client width is the same as it's width, then the vertical scroll bar is not visible. You can determine the size of the scroll bar by examining the style. For example:

if (VertScrollBox1.ClientWidth = VertScrollBox1.Width) then
  VerticalScrollBarVisible := False;
  VerticalScrollBarWidth := 0;
else
begin
  VerticalScrollBarVisible := True;  
  VerticalScrollBarWidth := VertScrollBox1.StylesData['vscrollbar.width'].AsExtended;
end;