Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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
 
Share this answer
 
var observe = new observation();
observe.Show();
this.Close();
 
Share this answer
 
Comments
jayanthik 1-Jul-11 6:22am    
tx
Christian Graus 2-Jul-11 2:57am    
Except, if this is your main form, then the whole form will close.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900