开发者

Can we and how to open a new window and closes the previous window in the same thread?

开发者 https://www.devze.com 2023-02-23 03:16 出处:网络
I am asking this, because i want to know if when we are running an app, for start if we have an window to authenticate like a Log In window, after validating the user, can we open the Main Window in t

I am asking this, because i want to know if when we are running an app, for start if we have an window to authenticate like a Log In window, after validating the user, can we open the Main Window in the sam开发者_如何学Goe Thread without creating a new one?

I am trying to do this in WPF, but i think that is same thing in WPF or in Windows Forms.


Yes, you can.
Just do it.


When you generate a Windows Forms application via the IDE, it will generate the code for one form, as well as a Main function that displays the form at runtime. You can rewrite the Main method so it displays one form modally then displays the next form.

But there's a simpler way to achieve your objectives:

Have two windows: your Main window, where most of the work is done, and the login screen.

In the OnLoad event of your main window, create an instance of your login window and call ShowModal() on this instance.

If the login fails, then exit the application.


This question does not offer enough context to tell you how to do this in your specific case. In general you can just Close() a window, construct a new one and call Show() on it.

You should make sure the Application.ShutdownMode does not kill off your application when the window is closed though.

0

精彩评论

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