Search code examples
delphi

How to find the real size ("logical area") of a TScrollBox


I need to find the entire size (also called "logical area") of a TScrollBox - as opposite to visible area that you get via Width and Height property (or ClientWidth ClientHeight).

I want to create some controls inside that TScrollBox. One of them (called TViewer) needs to be as high as the TScrollBox itself. The thing is that during creation, the TScrollBox is scrolled down to show last created control. So, using Top=1 will not work because my control will have top=1 which is not the top of the logical area.


Delphi 7


Solution

    1. Drop a component, like a TLabel, on the TScrollBox.
    2. Set the component's Left and Top properties to 0.
    3. Set the component's Visible property to False.

    Now you always have the origin. The "logical height" is now:

     VisibleHeight:= myScrollBox.Height + (myOriginControl.Top * -1);