Filipe Martins
Filipe Martins

Reputation: 608

Scrolling Programmatically THorzScrollBox Firemonkey XE6

I have a THorzScrollBox in a form, and some TStyledControls inside. Each StyledControl has a Tag to identify. Using an TEdit to inform a value, I can find inside the ScrollBox an specific Control by his tag.

If the control that I searched is not on the screen, I want to scroll the ScrollBox to show it.

How can I do this programmatically?

Upvotes: 2

Views: 3430

Answers (1)

Filipe Martins
Filipe Martins

Reputation: 608

I found a way to do this. I have to use ScrollBy. But the detail is that if I want to scroll the controls to right I have to use a negative value. Example:

sbItems.ScrollBy(-10, 0); // this will scroll to right

If I use a positive value, it will scroll to left.

sbItems.ScrollBy(10, 0); // this will scroll to left

The point is, if you scroll once, the ViewportPosition will change and the next time you execute ScrollBy, it will not reset the scroll position, it will scroll from the point you already have scrolled.

Upvotes: 6

Related Questions