Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are controls in the wrong place if they're positioned while the form is scrolled?

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?

like image 464
Rakesh Devarasetti Avatar asked Oct 20 '11 12:10

Rakesh Devarasetti


1 Answers

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

like image 55
VibeeshanRC Avatar answered Sep 30 '22 12:09

VibeeshanRC