Huh? Do I misunderstand Self.Left?

I’m baffled.

Two textfields and one listbox. Listbox does not get a tab stop.

The only code is in one textfield:

To show the listbox:

Sub GotFocus() Handles GotFocus Listbox1.Left = Me.Left Listbox1.top = Me.top + Me.Height + 2 End Sub

To hide the listbox out of sight (left of the window):

Sub LostFocus() Handles LostFocus Listbox1.Left = Self.left - 200 End Sub

Simple. Tabbing between the two textfields should show the Listbox or move it out of sight (left of the window).

Run it. Tab Tab … seems to work.

Now move the window. Tab Tab … SUGAR ! ? (as we are not allowed to write W T F because of all the small kids on the forum who might be damaged in their emotional development and could be scared for life. I kid you not. And if you are a little kid and want to know what W T F stands for, it’s for “We’re Totally Foobared” [and if you are confused go and ask your parents]. And as I got a final warning then if you do not hear from me anymore then sugar must now be a bad word too and Big Nanny has banned me from using the forum … :D)

Anyway.

Tried it with Xojo 2016 R3, Xojo 2017 R3, Xojo 2018 R1 on two different Macs (one running Sierra, the other El Capitan).

Also tried Window1 and TrueWindow instead of self, same result.

Any idea why self.left is not showing the result I’m expecting?

Sample project at https://www.dropbox.com/s/t1qsubqqohp9gm2/test%20self%20left.xojo_binary_project.zip?dl=0

You are correct here, expecting self to be the Window instance.

However, the control’s left is relative to the window, and Window.Left is it’s position on the screen. You only need to set the Listbox.Left to -200 for the effect to work.

Grab the Window.Left and inspect it’s value before applying the -200 to see what’s going on, and see why you’re still seeing the Listbox. No framework fuckups here!

I realize this doesn’t directly address your question, but is there a reason you aren’t hiding and showing the listbox using the “visible” property?

Listbox1.visible=true ‘’'shows the listbox

and

Listbox1.visible=false ‘’'hides the listbox

@Tim: Got it. I screwed it up. Logic error on my part, assuming self.left - 200 would be 200 pixels left of the window (because Listbox1.left is then not the absolute x position but relative to the parent window, so I should have used Listbox1.left = - Listbox1.Width - 10 )

@Seth: I was trying something. I know, curiosity killed the cat, but I’d argue that I’m not a cat so it’s less dangerous for me … :wink:

[quote=382825:@Markus Winter]@Tim: Got it. I screwed it up. Logic error on my part, assuming self.left - 200 would be 200 pixels left of the window (because Listbox1.left is then not the absolute x position but relative to the parent window, so I should have used Listbox1.left = - Listbox1.Width - 10 )
[/quote]
Well that might not always result in what you’re expecting because it would only work when the listbox is 10px or less from the left of the window. You might want Listbox1.Left = -Listbox1.Left - Listbox1.Width - 25 // a nice padding to prevent accidents, however if you lock both sides of the Listbox to allow it to flex grow it can go wrong once the Listbox is no longer visible to the left and someone resizes the window.

Nope, Listbox1.left = - Listbox1.Width - 10 aka “10 further left of the window than the width of the Listbox” works fine, no matter where the Textfield is.

As for locking the Listbox to both sides, in that case you would need to add some code to the resizing event of the window, but that is outside my usage scenario.