如果在表单滚动时定位控件,为什么它们会位于错误的位置?

发布于 2024-12-11 06:42:51 字数 501 浏览 1 评论 0原文

考虑此表单,带有标签“此处观察者”和按钮“单击”:

时,我将标签的 Left 设置为 10 (Label1.Left :=10;)

我得到了正确的结果,如第二张图片所示:

靠近左边缘带有标签的表单

然后,我将表单向右滚动:

与之前的形式相同,但向右滚动,因此标签被隐藏

现在,单击按钮后出现问题,如第四张图片所示:

相同的形式,向左滚动,但标签在中间而不是左侧可见

标签的 Left 不再是 10 。它超过 10 个,但我需要它是 10 个。我该怎么做?

Consider this form, with a label 'Observer here' and a button 'Click':

a label near the left edge of the form, with a button

On button click I am setting the label's Left to 10 (Label1.Left :=10;)

I am getting correctly as in the second image:

form with label near left edge

Then, I scroll the form to the right:

same form as before, but scrolled right so label is hidden

Now, after clicking the button I get a problem, which is shown in 4th image:

same form, scrolled left, but label visible near middle instead of left

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单挑你×的.吻 2024-12-18 06:42:51

标签1.左:= 10;表示距离当前边框(form1.left) 还剩10。

所以 Label1.Left := 10 ;不会总是产生相同的结果,它取决于 Form1.HorzScrollBar.Position ;

你必须这样编码

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

Label1.Left := 10 - Form1.HorzScrollBar.Position  ;

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文