window placement

Hi all,

I can’t figure this out, I have a mainwindow which displays top left of screen when opened (would like to centre it, but thats probably another thread).
I call a new window with ‘window1.showmodalwithin(main window)’
No matter what window type I select (Modal dialog, document, etc) it displays in the centre of the screen. I would really like it to display in the centre of mainwindow from which it was called and is the parent.
I have tried changing the placement also.

Any ideas? Preferably without having to set top and bottom values.

Cheers

You want to walk, but preferably without legs ? Come on…

window2.visible = False // Will instantiate implicit, so hide it window2.left = self.left+(self.width-Window2.Width)/2 window2.top = self.top+(self.height-Window2.height)/2 window2.showmodalwithin(self)

I have a very simple method to centre any window on another one. But of course I use top and left.

Sounds like a ‘VB used to do this’ situation.
It had a ‘startPosition’ property of a form which woulb be set to ‘CenterParent’ or similar.
Xojo doesnt.

In the inspector for main window, set the placement value to “main screen”

to open Window1 in center of mainwin

dim r as new REALbasic.Rect
  r.Width = mainwin.Width
  r.Height = mainwin.Height
  r.Left = mainwin.Left
  r.Top = mainwin.Top
  
  Window1.Show
  Window1.Left = r.Left + r.Width / 2 - Window1.Width /2
  Window1.Top = r.Top + r.Height / 2 - Window1.Height /2

Center Window
Window.Open

Dim myBounds As New Realbasic.Rect
  myBounds.Width = 600
  myBounds.Height = 400
  myBounds.HorizontalCenter = Screen(0).AvailableWidth
  myBounds.VerticalCenter = Screen(0).AvailableHeight
  
  me.Bounds = myBounds

All works well now, however…
when the window is called (modal dialog) it does not have focus. It displays on top of mainwindow but mainwindow keeps the focus, I have to click on the dialog to shift the focus to it, then all works well.

Just noticed, this only occurs in the startup routine.

In the open event of mainwindow i call window1 which does not get the focus as described above.
However, once I’m finished with window1 and close it, i have a button on mainwindow that calls it again. If called with the button, it gets the focus fine.
So it only happens when called from the mainwindow open event. Is there a way of fixing this? Should i be using a different event?
I want window1 to open at start, but over top of mainwindow.

Cheers

test

Solved…

set the apps default window to none (was mainwindow)
in the app open event, call mainwindow, then call window1
Works as expected.
Must have been the default window setting in the app.

Cheers.

If you use MDI (Multiple Document Interface applications) and need center a window ?

  1. in app (Event Handlers - Open), modify your MDI Window, example

MDIWindow.Title = "your name software system" MDIWindow.Maximize

  1. in myWindow ( Event Handlers - Open)

Me.Visible = false ' Hide MyWindow Me.Left = (screen(0).Width - Me.Width) / 2 'center horizontally Me.TOP = (screen(0).Height - Me.Height) / 2 'center vertically Me.Visible = true ' Show MyWindow

REMEMBER:

screen(0).widht its a Screen of your PC, not a WiNDOW size :slight_smile: