如何在不终止应用程序的情况下仅关闭 vb.net 2010 中的主窗体 [英] how to close only the main form in vb.net 2010 without terminating the application

查看:29
本文介绍了如何在不终止应用程序的情况下仅关闭 vb.net 2010 中的主窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录表单,我需要在不终止整个应用程序的情况下关闭它.我也尝试使用 Me.Close() 和 Me.Hide() .登录表单也用作主表单.

I have a login form which I need to close without the entire application being terminated. I tried using Me.Close() , Me.Hide() as well. The login form is used as the main form as well.

推荐答案

我希望这是有道理的....

I hope this makes sense....

听起来您有一个 VB.Net 项目,而您的登录表单就是您的启动表单".当您关闭该表单时,您的应用程序认为它已经结束;但您确实想在登录表单关闭后采取行动.

It sounds like you have a VB.Net project and your Login form is your 'startup form'. When you close that form, your application thinks it is over; but you really want to take action after the Login form is closed.

如果您打开项目的属性"窗口,您可以在应用程序"选项卡上设置关闭模式".默认为启动表单关闭"时.将其更改为当最后一个表单关闭时".

If you bring up the Properties window for the project, on the Applications Tab you can set the 'Shutdown mode'. The default is when the 'Startup Form Closes'. Change it to 'When the last form closes'.

您还可以在此处添加应用程序级别的事件.http://msdn.microsoft.com/en-us/library/f2bys999(v=vs.80).aspx

You can also add Application level events here. http://msdn.microsoft.com/en-us/library/f2bys999(v=vs.80).aspx

如果你坚持你的方式;您的登录表单将不得不在关闭之前创建另一个表单,否则您的应用程序将关闭.你可以做到这一点;但是将登录逻辑移到应用程序启动事件中可能会更清晰(有关更多详细信息,请参阅链接).

If you stick with the way you are going; your Login form is going to have to create another form before it closes or your app will close. You can do that; but it's probably cleaner to move the login logic into the Application Startup Event (see link for more details).

在启动事件中,您可以显示登录屏幕、获取结果、决定是否要显示应用程序的主窗体等...

In the startup event you can show the Login screen, get the result, decide if you want to show the main form for your application, etc, etc...

这篇关于如何在不终止应用程序的情况下仅关闭 vb.net 2010 中的主窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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