2011-06-09 61 views
0

我有2个窗口我的示例应用程序(学习.NET 4的WPF)使窗口1消失,启动另一个窗口

在第一个窗口中,我有一个计时器,如果将5秒钟过去了,我想关闭当前窗口并打开一个新窗口。

我运行到被关闭第一个窗口

这里的问题是一些示例代码

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

this.Hide从来没有真正隐藏当前窗口。我结束了2个窗口我的屏幕,而不是1

回答

2

ShowDialog的言论就可以说When this method is called, the code following it is not executed until after the dialog box is closed.

所以,你可以交换的ShowDialogHide的顺序。你必须在'ShowDialog'之后使用'Show'或'Close'来显示第一个表单或关闭它。

此外,请注意,closing a form(你说的要做的)与hiding a form(你现在正在做的)不同。

1
MainWindow m = new MainWindow(); 
this.Hide(); 
m.ShowDialog(); 
相关问题