开发者

Make Window1 disappear and launch another Window

I have 2 Windows in my sample App (开发者_如何学Clearning .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.


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).


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜