问题描述
我的表单中有一个 THorzScrollBox
,里面还有一些 TStyledControls
。每个 StyledControl
都有一个 Tag
来标识。使用 TEdit
通知值,我可以在 ScrollBox
中找到特定的 Control
通过他的标记
。
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
.
如果控件$我搜索的c $ c>不在屏幕上,我想滚动
ScrollBox
来显示它。
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?
推荐答案
我找到了一种方法。
我必须使用 ScrollBy
。但细节是,如果要向右滚动控件,则必须使用负值。
示例:
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
要点是,如果滚动一次,则 ViewportPosition
将会更改,下次执行 ScrollBy
时,它不会重置滚动位置,而是从您已有的位置开始滚动滚动。
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.
这篇关于以编程方式滚动THorzScrollBox Firemonkey XE6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!