Setting the TVertScrollBox Position

Recently in FMX, I was trying to reset the scrolling position of the TVertScrollBox to the top when re-showing a frame:

The solution is to use the ScrollBy function.

You have to specify how many pixels you would like to move backwards from the current position. For example, if my current Y position is 100 and I want to move to the top, then I would invoke ScrollBy(0, 100).

To move forwards (down for Y, right for X) you need to supply a negative value, i.e. ScrollBy(0, -100).

To determine your current position:

var y := Scroller.ViewportPosition.Y

var x := Scroller.ViewportPosition.X

To scroll to the top:

Scroller.ScrollBy(0, Scroller.ViewportPosition.Y);

An alternative is to just set the ViewportPosition property absolutely:

Scroller.ViewportPosition := PointF(0, 0);

If the contents are not aligned correctly:


I hope this tip may be useful.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s