如何在不关闭完整应用程序的情况下关闭第一个表单? [英] How I can close a 1st form without closing the full application?

查看:58
本文介绍了如何在不关闭完整应用程序的情况下关闭第一个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何在不关闭应用程序的情况下关闭登录表单并显示主表单?

我如何在不关闭整个应用程序的情况下关闭第一个表格?
C#.例如,如果我的第一个表单是在输入用户名和密码后登录表单的,那么如果他们正确,则该表单应该关闭,而其他表单需要打开.

How i can close a 1st form with out closing full the application?
C#. as a example if my 1st form is logging form after enter username and password if they are correct that form should be close and other form need to be open.

我尝试了 this.close(),但是我的完整应用程序正在退出:(.之后,我尝试了 this.Hide(),它可以正常工作,但是我的表单仍在运行只是从用户界面中隐藏.

I tried this.close() but my full application is exiting :(. After that I tried this.Hide() it works but my form is still running just hidden from UI.

ty

推荐答案

实际上很简单.在Program.cs Main静态方法上,使用以下代码启动LoginForm.

It is actually quite simple. On your Program.cs Main static method use the following code to launch your LoginForm.

var myLoginForm = new LoginForm();
myLoginForm.Show();
Application.Run();

然后从您的LoginForm中,只需记住在关闭下一个窗体之前启动它,如下所示:

Then from your LoginForm, simply remember to launch your next Form before closing it like this:

var myNextForm = new NextForm();
myNextForm .Show();

this.Close();

如果您只想在登录失败后关闭应用程序,请执行以下操作:

If you rather just want to close the application after login fails just do the following:

this.close();
Application.Exit();

希望有帮助!

这篇关于如何在不关闭完整应用程序的情况下关闭第一个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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