vb.net Visual Basic 问题 - Me.Hide() 或 Me.Close()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19593018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Issue with Visual Basic - Me.Hide() or Me.Close()
提问by The Simon
I'm totally new at this, so my question are suppose to me very simple..
我对此完全陌生,所以我的问题对我来说很简单..
I have made a very simple login form. When password and username is right, i want to close password form and load main_form..
我制作了一个非常简单的登录表单。当密码和用户名正确时,我想关闭密码表单并加载 main_form..
But I don't know exactly how to write this..
但是不知道具体怎么写。。
So far I have this when you click at the login button in the first form:
到目前为止,当您单击第一个表单中的登录按钮时,我已经有了这个:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If username.Text = "user" And password.Text = "pass" Then
Me.Hide()
dreamware_main.Show()
Else
pass.Text = "Wrong user name or password!"
End If
End Sub
It works great the first time I run the project, but the second time, it wont run project and gives me the error that my application is still running..
我第一次运行该项目时效果很好,但第二次运行时,它无法运行项目并提示我的应用程序仍在运行的错误。
I'm guessing it's because of the Me.Hide() that just hides my login_form, but never closes it... that's why it wont run the second time,
我猜这是因为 Me.Hide() 只是隐藏了我的 login_form,但从未关闭它......这就是它不会第二次运行的原因,
I've tried with Me.Close() instead, and when I do that it will run the project the second time, but that just closes all my forms, and I don't want that..
我已经尝试使用 Me.Close() 代替,当我这样做时,它将第二次运行该项目,但这只会关闭我的所有表单,我不希望那样..
How can I close the first form, without closing dreamware_main?
如何关闭第一个表单,而不关闭 Dreamware_main?
回答by Idle_Mind
As Mark Hall pointed out, in Project --> Properties, change the "Shutdown mode" to "When last form closes":

正如 Mark Hall 所指出的,在 Project --> Properties 中,将“Shutdown mode”更改为“When last form closes”:

This will allow you to Close() the login form without causing the whole application to exit.
这将允许您关闭()登录表单,而不会导致整个应用程序退出。
回答by junaks2000
I would like to suggest you reconsider your login concept. Open the main form and display login form on top of that. Then the default would work for you, which is "when startup form closes".
我建议您重新考虑您的登录概念。打开主表单并在其上显示登录表单。那么默认值对您有用,即“启动表单关闭时”。
This is nice one.
这是一个不错的。
回答by Wiley
Did you try:
你试过了吗:
Me.Hide
Unload Me
回答by Neolisk
Actually, I think it should be Me.Hide()and then Me.Close()- to cover some layout issues, which I don't remember off top of my head. If those are not bothering you, it's usually Me.Close().
实际上,我认为它应该Me.Hide()然后Me.Close()- 涵盖一些布局问题,我不记得我的头顶。如果这些不打扰您,通常是Me.Close().
Regarding your question - see Idle_Mind's answer for a possible solution.
关于您的问题 - 请参阅 Idle_Mind 的答案以获取可能的解决方案。
I would like to suggest you reconsider your login concept. Open the main form and display login form on top of that. Then the default would work for you, which is "when startup form closes".
我建议您重新考虑您的登录概念。打开主表单并在其上显示登录表单。那么默认值对您有用,即“启动表单关闭时”。
From personal experience, it is a more extensible development pattern, as you may want to allow some guest access to your application later, or allow log off and log in under a different account.
从个人经验来看,这是一种更具扩展性的开发模式,因为您可能希望稍后允许某些访客访问您的应用程序,或者允许注销并使用不同的帐户登录。
Or, with single sign-on, you will authenticate with a Windows account, so no need to show a login form.
或者,通过单点登录,您将使用 Windows 帐户进行身份验证,因此无需显示登录表单。
Another side note - users generally like to see where they are about to log in.
另一边注 - 用户通常喜欢查看他们将要登录的位置。
回答by pcoco
try Me.Hideinstead of Me.Hide()
尝试Me.Hide代替Me.Hide()

