当前窗口应关闭,下一个窗口应打开 [英] current window should be close and next window should be open

查看:84
本文介绍了当前窗口应关闭,下一个窗口应打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用类似的方法通过单击按钮打开下一个窗口

varobtain =新的observation();
watch.Show();
但是如何关闭当前窗口,观察是下一个窗口,当前窗口是window1

i am using like this to open next window on clicking on button

var observe = new observation();
observe.Show();
but how to close current window, observation is next window current window is window1

推荐答案

问题是:如果不关闭应用程序就无法关闭主窗口.因此,使用Window.Hide而不是关闭.您可以防止用户处理事件Closing来关闭表单,或者更好的是,覆盖方法OnClosing.您可以通过将CancelEventArgs.Cancel分配给true来防止真正"关闭表单.

请参阅 http://msdn.microsoft.com/en-us/library/system .windows.window.closing.aspx [ ^ ], http://msdn .microsoft.com/en-us/library/system.windows.window.onclosing.aspx [
The problem is: you cannot close main window without closing the application. For this reason, Window.Hide is used instead of closing. You can prevent closing the form by the user handling the event Closing or, better, overriding the method OnClosing. You can prevent "real" closing of the form by assigning CancelEventArgs.Cancel to true.

See http://msdn.microsoft.com/en-us/library/system.windows.window.closing.aspx[^], http://msdn.microsoft.com/en-us/library/system.windows.window.onclosing.aspx[^].

Generally, such design showing forms alternatively is not recommended. It''s much better to use just one form showing different parts of it and hiding others. One of the nice forms of is is tabbed UI based on TabControl.

—SA


var observe = new observation();
observe.Show();
this.Close();


这篇关于当前窗口应关闭,下一个窗口应打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆