考虑以下表单,其标签为“观察器”和按钮为“单击”:
点击按钮后,我将标签的“Left”设置为10(
然后,我将表单向右滚动:
现在,点击按钮后出现了问题,如第四幅图所示:
标签的“Left”不再是10。它大于10,但我需要它是10。怎么办?
![a label near the left edge of the form, with a button](https://istack.dev59.com/N4Pjg.webp)
Label1.Left :=10;
),此时显示如下图所示:
![form with label near left edge](https://istack.dev59.com/jkfvp.webp)
![same form as before, but scrolled right so label is hidden](https://istack.dev59.com/HbfLJ.webp)
![same form, scrolled left, but label visible near middle instead of left](https://istack.dev59.com/TkNkA.webp)
Label1.Left := Form1.Left + 10;表示比当前窗口边界(Form1.Left)向左移动了10个单位。
因此,Label1.Left := 10;不总是产生相同的结果,它取决于Form1.HorzScrollBar.Position;
你需要这样编码:
Label1.Left := 10 - Form1.HorzScrollBar.Position ;