简体   繁体   English

打开 FormMain (MDI) 后关闭登录表单

[英]Close login form after opening FormMain (MDI)

I have a login form linked to database, when the login is successful it opens my FormMain which is a MDI form.我有一个链接到数据库的登录表单,当登录成功时,它会打开我的FormMain ,它是一个 MDI 表单。

I have this code in my Program.cs:我的 Program.cs 中有此代码:

FormLogin formLogin = new FormLogin();
if (formLogin.ShowDialog() == DialogResult.OK)
{
    Application.Run(new FormMain());
}
else
{
    Application.Exit();
}

What I would like to achieve is, Once the FormMain is opened it should close the login form.我想要实现的是,一旦打开FormMain ,它应该关闭登录表单。 At the moment after the main form is opened you can alt tab and go to the login form again.在主表单打开后的那一刻,您可以使用 alt 选项卡并再次转到登录表单。 I have tried adding formLogin.Close();我试过添加formLogin.Close(); before Application.Run.... without success.Application.Run....之前没有成功。

Thank you for your time!感谢您的时间!

Given the way this is implemented you can hide the login form although it may be possible to close it in another method given the way you currently have it.鉴于这是实现的方式,您可以隐藏登录表单,尽管根据您当前的方式,可以用另一种方法关闭它。 Another option is to open the main form in a new thread and close the current thread.另一种选择是在新线程中打开主窗体并关闭当前线程。 this will completely close the login page and pass all control to the only active thread.这将完全关闭登录页面并将所有控制权传递给唯一的活动线程。 also, please note.另外,请注意。 if you are using threads then the main form cannot be a child thread如果您使用线程,则主窗体不能是子线程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM