Reputation: 9551
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
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