1

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 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

What does this have to do with finding out if a FMX TListBox scrollbar is visible?
Yes, of course. I forget about this properties - going wrong way. Thanks! It's solve my trouble but don't answer to question - how to know is scrollbar visible or not.
@KenWhite because OP mentions that his method of calculating height is not working because of form's border and caption.
1

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; 

4 Comments

In this solution the border thickness is lost. When I use the following check VScrollVisible := ListBox.ClientWidth + BorderWidth < ListBox.Width this approach is working well. Unfortunately I did not found a simple approach to get the border width. My workaround calculates the BorderWidth at startup (with an empty list) by ListBox.Width - ListBox.ClientWidth.
Calculating the border width (of the ListBox) might be dependent on the platform. On Windows and OSX, the "background" style element is a TStyleObject. On iOS and Android it's a TRectangle that has a "Stroke.Thickness" property that you could possibly get the border width from. Is it possible to put your TListBox inside of a TRectangle to make your calculations consistent across platforms?
Yes, I know the border depends on platform and style. I don't see the need of a paling rectangle. ListBox.Width returns the outer dimension while I get the inner dimension from ListBox.ClientWidth. The difference must be the border as long no scrollbar is present. My workaround is to measure this border size at startup (at FormShow) with an empty list.
Sorry, my approach mention in the last comment does not work at all circumstance. I would expected that the border size can be fetched from the this style data too but I didn't found a working solution yet.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.