Is there a way to give the default window focus?

Hello all,

Is there a way to give the default window focus when the app starts up? Am using 2023 R3.2 on Windows 10 and Raspberry Pi V4.

Thank you,

It should have the focus; do you mean to set it a specific control? If so, you would do that in the Window.Opening event:


Thanks for the reply Mike,

No, I want the whole window to have focus - as it is now, the user has to click on the app, anywhere, for windows to give it focus.

In my specific case, I need to be able to trap the ESC key, which it does - BUT only after first clicking anywhere on the window so that the OS gives the app focus.


A little more info…
When the app starts, it launches the default window. After that, but during startup, it opens another window that needs to be on top of the main window. As it is now, the second window has the focus. How can I change that to the default window instead?



should do it

You can try different window frame types, but I’m not sure that functionality is supported on Windows.

Got something that will work.

After both windows are open, I added a method to frmMain that executes the method:

That cured the problem.

Thank you all for your responses! I appreciate them very much,


Well not quite… It works but only in debug build. Once built it does not work… I get a nil object exception. Not sure why since this is done following the window being created, shown, loaded with stuff etc.

Any ideas anyone?

A declare would probably do it.

Perhaps @Christian_Schmitz has an MBS plugin that could do that ?