如果在表单滚动时定位控件,为什么它们会位于错误的位置?
考虑此表单,带有标签“此处观察者”和按钮“单击”:
时,我将标签的 Left
设置为 10 (Label1.Left :=10;
)
我得到了正确的结果,如第二张图片所示:
然后,我将表单向右滚动:
现在,单击按钮后出现问题,如第四张图片所示:
标签的 Left
不再是 10 。它超过 10 个,但我需要它是 10 个。我该怎么做?
Consider this form, with a label 'Observer here' and a button 'Click':
On button click I am setting the label's Left
to 10 (Label1.Left :=10;
)
I am getting correctly as in the second image:
Then, I scroll the form to the right:
Now, after clicking the button I get a problem, which is shown in 4th image:
The label's Left
is not 10 anymore. It's more than 10, but I need it to be 10. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标签1.左:= 10;表示距离当前边框(form1.left) 还剩10。
所以 Label1.Left := 10 ;不会总是产生相同的结果,它取决于
Form1.HorzScrollBar.Position ;
你必须这样编码
你可以通过在 form1 中选择一个组件并调整滚动条在设计时看到这种模式,你可以注意到,在对象 Inspector 中,当移动滚动条时,所选组件的左值也会改变
你可以这样理解
如果你有 HorzScrollBar 那么如果你添加组件并设置它们的左值非常高,form1不会增加其宽度,但其由滚动条处理的虚拟宽度会增加,所有协调值将给出相对于form1的值,与虚拟空间无关
Label1.Left := 10 ; Means 10 left from the current border(form1.left).
so Label1.Left := 10 ; will not produce the same result always ,It depends on
Form1.HorzScrollBar.Position ;
You have to code like
You can see this pattern on design time by select a component in your form1 and adjust the scroll bar ,you can notice that in the object Inspector left value of the selected component will also change when moving the scrollbar
You can understand it like this
If you have HorzScrollBar then if you add components and set their left value very high, the form1 will not increase its width but its virtual width handled by scrollbar will get increased, all the coordination values will give the value relative to form1 not related to the virtual space