问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/28681719/scrolling-programmatically-thorzscrollbox-firemonkey-xe6