Cocoa Dev
Cocoa Dev

Reputation: 9551

Make Window1 disappear and launch another Window

I have 2 Windows in my sample App (learning .Net 4 WPF)

In the first window, I have a timer and when 5 seconds passed, i want to close the current Window and open a new Window.

The problem I'm running into is closing the first window

Here's some sample code

MainWindow m = new MainWindow();
m.ShowDialog();
this.Hide();

this.Hide never actually hides the current window. I end up with 2 windows on my screen instead of 1.

Upvotes: 0

Views: 337

Answers (2)

George Duckett
George Duckett

Reputation: 32448

In the remarks of ShowDialog it says When this method is called, the code following it is not executed until after the dialog box is closed.

So, you can just swap the order of ShowDialog and Hide. and you have to use 'Show' or 'Close' after 'ShowDialog' to either display back first form or close it.

Also, note that closing a form (what you said want to do) is different to hiding a form (what you're currently doing).

Upvotes: 2

Bolu
Bolu

Reputation: 8786

MainWindow m = new MainWindow();
this.Hide();
m.ShowDialog();

Upvotes: 1

Related Questions