Modal Window doesn't always receive focus

I’ve been searching for a solution to this for more than an hour but to no avail. I have a few other (movable) modal windows in my app that work as expected, but in this case the conditions are slightly different.

The modal window is a simple help screen which allows the user to show at startup or not. The other way of showing the window is by selecting a help menu item.

What’s happening is that on start up, the modal window is shown in front of the main window (all good), yet the main window still has the focus. No amount of ClearFocus, SetFocus seems to make any difference - it still will not receive the focus unless physically selected via the mouse.

In the open event of WindowMain:

If showHelpAtStartup = "True" Then // Show the help window as read from preferences WindowHelpOVERALL.ShowModal End If

However, if the modal window is instantiated in the main window via the Menu Handler, it works as expected.
In the Menu Handler, it’s the same code except for the If/End If block:


Like is said, it doesn’t seem like I can force the modal window to have the focus.

I’m just wondering if calling the modal window from the open event of the main window is the issue. If it shouldn’t be called from there, then where?

[2016R3 Win7]

A lot of modal window bugs were fixed in 2018r1 <>

If you can pop up a simple demo I’ll take a look and see if I can find a way around the problem you’re experiencing.

The easiest way around this is to put this in your Window1.Open:

xojo.core.Timer.CallLater(0, addressof Window2.ShowModal)

this gives the framework time to open Window1 and then open Window2 after it which moves the focus to the new window.

Perfect!! The easiest way is often the best. Also thanks forthe explanation.
Thanks once again for your help Julian.