Resize a window with a ToolBar

I have a problem in a project. Instead of simply asking as usual with a minimum code, I created a project and paste below the offending code.

Below is a screen shot of the window with the ToolBar (and a non visible Canvas, below the ToolBar). When one click in a Button, the corresponding image is loaded in the Canvas located below the ToolBar.

In the project archive, you will get the icons for the ToolBar (32 x32) and the images that will be loaded by a Button click.

What happens when one make successives click in buttons ?
The window height is resized down vertically and at last the window disappears.
This was not done before I added the Realbasic.Rect code. In that case, the window width and height was not resized at all.
Six clicks are enoug to resize the window to the point its height is nul or so. In fact, the image shrink by a factor of 78 pixels:

400, 322, 244, 166, 88, 10 and nothing…
Those numbers are the height value after a click in a button / display an image…

The project file is here.

What have I done wrong ?

[code]Sub Display_Image(The_Img As String, The_Canvas As Canvas)
// Dim the needed variables
Dim ImgFI As FolderItem
Dim TheWidth As Integer
Dim TheHeight As Integer

// To move the window to 0,0
Dim myBounds As New Realbasic.Rect

// Get a reference to the image to load
ImgFI = GetFolderItem(“Data”).Child(The_Img)
// demo: no error checking

// Load the image into the Canvas
The_Canvas.Backdrop = Picture.Open(ImgFI)

// Fills myBounds values
myBounds.Width = wMain.Width // The_Canvas.Width // Not better
myBounds.Height = wMain.Height // The_Canvas.Height // Not better
myBounds.Top = Screen(0).AvailableTop
myBounds.Left = 0

// Set wMain to topmost, Leftmost !
wMain.Bounds = myBounds
End Sub

// Not better: the poblem exists too with that code instead of wMain.Width / wain.Heigth ![/code]

MacBook Pro 2011-11 OS X 10.9.5 Xojo 2014r2.1

By the way: I do not get that in my original project, but when the first image to be displayed in the original project, the window is corectly located to Leftmost / rightmost, but the window height is bad (does not display the image full height).

Instead of modifying the bounds, just set the .top .left .width and .height properties of the window as needed

Hi Emile, this is where the bug happens

wMain.Height gives you the height of only the content area.

wMain.Bounds.Height gives the height of the whole window, which is including the tool/titlebar.

So you’re mixing different measures. If you want to use myBounds to place the window then you’ll need to use that height which includes the tool/titlebar.

myBounds.Height = wMain.Bounds.Height

Or as shao said don’t bother with .Bounds. In fact, since you’re not changing the size, all you need is…

wMain.Top = wMain.Bounds.Height - wMain.Height + Screen(0).AvailableTop wMain.Left = 0

shao, Will:

In fact, I want to set the left and top location to the leftmost / topmost positions AND resize the window to fully display the loaded image (that image is at most 600 pixels height (at most).

ALSO: I do not have troubles with the width.

Ideas ?

wMain.Top = 0 wMain.Left = 0 wMain.Height = The_Canvas.Backdrop.Height wMain.Width = The_Canvas.Backdrop.Width

For me this places the window so the top of the content area is at the very top of the screen, underneath the menubar.

Is Screen(0).AvailableTop any better?

Yes, but height of the tool/titlebar still needs to be added so it’s not under the menubar

wMain.Top  =  Screen(0).AvailableTop + (wMain.Bounds.Height - wMain.Height)

I generally don’t move around the windows on the user, so never needed to do that…

shao: the example project is bad in the sense all is done there. In the real project, the user choose to watch an image and that window with the toolbar id displayed with a wrong height. In that window, I have Buttons to go to the next / previous, etc images and there, the image is displayed correctly.

I only wanted to display what I call an error.

That is the reason I use Realbasic.Rect, as an advice from this forum.

Did you try (all) the shared project with your changes ?

NOTA: this is a multi-platform behavior (even if I do not checked it in Windows). The real project share a height trouble in both OS X and Windows (XP, 8.1).

Here are more details with three window screen shots. The behavior also exists on WIndows.

Window Screen Shot #1:
There is a Contextual Menu in the Canvas (as you can see) that allows to display more images in another window. Check the two othere screen shots below.

Window Screen Shot #2:
You can see the displayed image when asked for the first time by the Contextual Menu. There is missing height to fully display the image.

Window Screen Shot #3:
Some clicks on the left / right arrows buttons (or select in the popup button on the middle) and we can see the full image.

I cannot explain better / more the trouble.

Nota: I will release the application this week and I will deal with this strange behavior later, if some day. I broken my teeth (nearly white, not blue) since… months on that.

What do you want to happen? Originally it looked like you just wanted to move the window to the very top-left, now you want to size it to the picture also? Or instead?

I tried to explain how the height setting works so you can figure out what you need to do. Does it not make sense?

Language barrier:

In a window I ask to display an image into another window. That another window is location is set at 0,0 (x,y where y is sticked to the MenuBar). And displaying an image in that window at open time. The two images above shows that.

And to be able to understand, I added a third window so you know how the disp^layed image is and by how much the HEIGHT is missing pixels.

There are two (or three ?) differents situations here:

a. place the window at the left / top of the monitor (so the window is set to the leftmost and topmost parts of the screen),
b. set the window size (height and width) so it can fully display the image.

Before I used Realbasic.Rect * (and before I added the ToolBar), I do not had troubles with the window height.
When I choose an image file from the image displayer window, the height is correct.
The “bug” comes when I open the window to display the first image. When I choose one from the PopUp Button or click in the First, Previous, Next, Last buttons, the image is totally displayed.

At last, I incorporate your advice in the App Store Button (ToolBar.Action):

wMain.Top  =  Screen(0).AvailableTop + (wMain.Bounds.Height - wMain.Height)

and the window height shrink is still acting (the bug goes on). This is in the shared project).

Just in case I did not understand your advice, can you repeat me this one with simple words ?

  • I also get the window belowthe MenuBar: most if not all of the WIndow TitleBar was hidden by the OS MenuBar or out of the top of the screen when running in Windows (XP and 8.1). Realbasic.Rect removes this bad behaviour.

DIM toolbarHeight As Integer = self.Bounds.Height - self.Height DIM myBounds As NEW REALbasic.Rect myBounds = self.Bounds myBounds.Top = Screen(0).AvailableTop // takes the menubar and taskbar into account myBounds.Left = 0 myBounds.Height = The_Canvas.Height + toolbarHeight myBounds.Width = The_Canvas.Width self.Bounds = myBounds

shao:

thank you for your kind answer. but the shared code only resolve the window height shrink, it does not expand correctly the window height.

I had to change Self with wImg since the code belongs to the mFileIO.Display_Image method (you can download the project from the link at the start of this page)

I follow the running code and found: toolbarHeight = 78 which is the value I found earlier. You definitely found something and correct a part of the error.

myBounds.Height = 478 and of course will not be able to display an image that is 1024 pixels tall. (478 is 400: the Canvas Height + 78: the ToolBar Height).

Searching, no, watching carefuly in the debugger leads me to see that the Canvas height is 400 (!) and the Cavas.Backdrop height is… 1024, the correct height !

There is a way to explorate here.

Stay tunned…

Found ! I added to the previous code a line to set the Canvas size to its own Backdrop size !

[code]// Get a reference to the image to load
ImgFI = GetFolderItem(“Data”).Child(The_Img)
// demo: no error checking

// Load the image into the Canvas
The_Canvas.Backdrop = Picture.Open(ImgFI)

// [2014-11-11] New Line that avoid the error:
The_Canvas.Height = The_Canvas.Backdrop.Height // This line squash the bug
[/code]

Thank you everyone and a special mention to shao sean who leads me in the right direction !

Squashing the bug can be successfully done at your local McDonald’s !

The idea came to my mind and goes away faster: waht about the width ?

I noticed that the idea was good and so I added it:

 The_Canvas.Width  = The_Canvas.Backdrop.Width

Add it below its sister line (read above the line that set the Height).

Looks like you got it… :slight_smile: