Window.Bounds - controls don't stay within window

Hi,

I want to show/hide some info on the left side of a window. The following code does that.

However there is a Textfield, ListBox, and a PushButton on the window which are anchored to the right side. On running the code they end up extending beyond the window border / outside the window.

I would have thought the controls stay within the window when the window is set to its new bounds. What am I doing wrong here?

[code]dim HeightToSubtract as integer = 77 // Toolbar + ???

Dim NewBounds As New Realbasic.Rect

// NewBounds initializes left and top to 0
NewBounds.Left = Window1.Left
NewBounds.Top = Window1.Top - HeightToSubtract
NewBounds.Height = Window1.Height + HeightToSubtract

if InfoVisible then // hide it
NewBounds.Width = Window1.Width - canInfo.Width - 5
canInfo.Left = -140
canMain.Left = 0
InfoVisible = False

else // show it
NewBounds.Width = Window1.Width + canInfo.Width + 5
canMain.Left = canInfo.Width + 5
canInfo.Left = 5
InfoVisible = True

end if

Window1.Bounds = NewBounds[/code]

[quote=187990:@Markus Winter]Hi,

I want to show/hide some info on the left side of a window. The following code does that.

However there is a Textfield, ListBox, and a PushButton on the window which are anchored to the right side. On running the code they end up extending beyond the window border / outside the window.

I would have thought the controls stay within the window when the window is set to its new bounds. What am I doing wrong here?

[code]dim HeightToSubtract as integer = 77 // Toolbar

Dim NewBounds As New Realbasic.Rect

// NewBounds initializes left and top to 0
NewBounds.Left = Window1.Left
NewBounds.Top = Window1.Top - HeightToSubtract
NewBounds.Height = Window1.Height + HeightToSubtract

if InfoVisible then // hide it
NewBounds.Width = Window1.Width - canInfo.Width - 5
canInfo.Left = -140
canMain.Left = 0
InfoVisible = False

else // show it
NewBounds.Width = Window1.Width + canInfo.Width + 5
canMain.Left = canInfo.Width + 5
canInfo.Left = 5
InfoVisible = True

end if

Window1.Bounds = NewBounds[/code][/quote]

Is there any reason why you set bounds rather than set the window Width and Height ? That would keep the locks together.

It was recommended to reduce flicker on Windows, so I thought I’d give it a try.

Hmm, actually I just tried

[code] if InfoVisible then // hide it
self.Width = self.Width - canInfo.Width - 5
canInfo.Left = -140
canMain.Left = 0
InfoVisible = False

else  // show it
  self.Width = self.Width + canInfo.Width + 5
  canMain.Left = canInfo.Width + 5
  canInfo.Left = 5
  InfoVisible = True
  
end if[/code]

and I get the same result.

It is not clear to me if you want the window to enlarge and shrink while the main content stays the same or if you want the main content to enlarge and shrink while the window width stays the same.

Either would be fine.

I got it working now by using ContainerControls instead of Canvases:

[code]if InfoVisible then  // hide it
  
  ccMain.Left = 0
  ccMain.Width = ccMain.Width + ccInfo.Width + 5
  
  self.Width = self.Width - ccInfo.Width - 5

  ccInfo.Left = -140

  InfoVisible = False
  
else  // show it
  
  ccMain.Left = ccMain.Left + ccInfo.Width + 5
  ccMain.Width = ccMain.Width - ccInfo.Width - 5
  
  self.Width = self.Width + ccInfo.Width + 5

  ccInfo.Left = 5

  InfoVisible = True
  
end if[/code]

I think part of the problem could be that unlike in REALstudio you can’t unlock all sides of a control in Xojo (but I might be completely wrong on this)

To keep the window size the same:

[code]Sub ShowInfoButKeepWindowSize()
if InfoVisible then // hide it

ccMain.Left = 0 
ccMain.Width = self.Width

ccInfo.Left = -140

InfoVisible = False

else // show it

ccMain.Left = ccMain.Left + ccInfo.Width + 5
ccMain.Width = ccMain.Width - ccInfo.Width - 5

ccInfo.Left = 5

InfoVisible = True

end if
End Sub
[/code]