Activating a window by code

Hello all,

Is there a way to activate a window while another window is being active?
Thanks!

You can’t have two windows active at the same time, but if you want to activate a window from an active window, use DesktopWindow.Show

1 Like

It’s understood that there is one active window at any time. I tried Show, but it does not activate it. The window that executes Show still is active.

Where do you call show? and how?

1 Like

If the window you want is an implicit instance, it’s simply TheWindowIWant.Show.

The execution flow is:
-App starts
-Window A opens
-Window B opens
-Done with B now. Keep it open, but want A activate.
A.Show() (From B; still not activating A)

Even this sequence doesn’t activate A:
-App starts
-Window A opens
-Window B opens
-Done with B now.
-Back at A.open() event handler:
A.Show(). Still don’t see A activated (the title of B still bold while A’s not.)

Sounds like you’re still in A.Open. You need to get out of the event sequence. Maybe open B from a short-period timer.

1 Like

Can you share a sample, it will be easier to point you in the right direction if we can see the code that you use.

Tim: A is open and yet cannot be activated while processing open event?

So your App’s default Window is WindowA and you have this in the opening event?

WindowB.Show
WindowA.Show

and you end with WindowB active above WindowA, right?

1 Like

Alberto, that’s correct.

As we don’t have much information about your goal, you can:

  • change the default window for your app to windowB and then show windowA, making windowA the top window
  • check if a timer makes more sense (maybe use a Timer.CallLater)

There is some explanation about why you are not getting what you expect in the documentation, but not sure right now where.

Are you familiar with Timers?

1 Like

If you have a default window, it should appear without your even calling Show.

1 Like

Alberto, yes, I can use Timer.
Jerry, both are shown, the desire is to activate A.

Correct, WindowA appears as is the default window,

  • then RobertF wants to show WindowB so in the Opening event of the default window (windowA) put WindowB.Show to make WindowB show,
  • but WindowB is on top of WindowA, the idea to use WindowA.Show at the end is to try to make WindowA the top and active window and not WindowB.

I’m not sure if it was clear that for the App we can change the default window to None, then in the App Opening event put:

WindowB.Show
WindowA.Show

and that will put WindowA on top of WindowB

image

image

to make both windows show but WindowA will be active and in front of WindowB.

1 Like

Understood. My point was more that Window.Show and Default Window are really redundant here. So yes, if we need to have a “default” window at all, make it WindowB and not Show it. You could possibly even put WindowA.Show in WindowB’s Open/Opening event.

1 Like

Solution found: Make WindowB default (previously it was A), at the end of B’s show event, A.Show() would activate A. Thank you, AlbertoD.
However, it should make sense that, whether a window is default or not, we should be able to activate a window from another one.
Thanks to all contributions, suggestions and comments!

That is correct. There is a lot going on behind the scenes in the Open sequence.

1 Like

Also note, FWIW, that the Activate event fires after the Open event.

1 Like