vb.net 如何在VB中打开一个新表单但关闭旧表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18491429/
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
How to open a new form but closing the old one in VB
提问by BaeFell
I have a welcome to my application as it loads up, but then need to have that form close and login form open when the continue button is hit.
当我的应用程序加载时,我欢迎它,但是当点击继续按钮时,需要关闭该表单并打开登录表单。
My code:
我的代码:
Me.Close()
Dim Login As New Form
Login.Show()
When I click the button it only closes the welcome form and then ends the application. If you can help thanks! :)
当我单击按钮时,它只会关闭欢迎表单,然后结束应用程序。如果能帮忙谢谢!:)
回答by Rahul Tripathi
You can set the properties of the project to select "When last form closes" in the shutdown mode dropdown
您可以设置项目的属性以在关闭模式下拉菜单中选择“当最后一个表单关闭时”
Update:-
更新:-
"Project" menu -> 'YourApp' Properties... -> Application Tab
“项目”菜单 -> 'YourApp' 属性... -> 应用程序选项卡
find : "Shutdown Mode"
找到:“关机模式”
Change from
更改自
"When startup form closes" --> "When last form closes"
“当启动表单关闭时”-->“当最后一个表单关闭时”
回答by Markjw2
show the form before the close.
在收盘前显示表格。
Dim Login As New Form
Login.Show()
Me.Close()
回答by Zigab123
Better is if you use Me.Hide()
更好的是,如果你使用 Me.Hide()
回答by Matt Wilko
There is a shutdown modeproject property. This controls the application lifecycle.
有一个关闭模式项目属性。这控制了应用程序生命周期。
Make sure you set this to "When last form closes"
确保将其设置为“当最后一个表单关闭时”
Then your code should work as you expect.
然后你的代码应该像你期望的那样工作。
What is happening is that you have that setting set to shutdown "when startup form closes", so by doing Me.Close
on the startup form, this shuts down the application, all code after this line is effectively ignored.
发生的事情是您将该设置设置为关闭“当启动表单关闭时”,因此通过Me.Close
在启动表单上执行此操作,这将关闭应用程序,该行之后的所有代码都被有效地忽略。
回答by Alex
If your Welcome Form isn't your main form, you just need to put your Me.Close
after your Login.Show()
如果您的欢迎表格不是您的主要表格,您只需要将Me.Close
您的Login.Show()
Dim Login As New Form
Login.Show()
Me.Close()
回答by Daniel
If you close sub main form from application, your application will close. However, you can close and open other forms if they are not the sub main form. Maybe you can just hide it instead.
如果您从应用程序关闭子主窗体,您的应用程序将关闭。但是,如果它们不是子主窗体,您可以关闭和打开其他窗体。也许你可以把它隐藏起来。
回答by BullfrogIIII
Try this..
尝试这个..
On your welcome form when closing:
关闭时在您的欢迎表格上:
Me.hide()
Dim Login As New Form
Login.Show()
On your login form when in loading event:
在加载事件时在您的登录表单上:
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WelcomeForm.Close()
End Sub
This will try to hide the first form and load the second form. And when second form is completely loaded it will try to close the first form.
这将尝试隐藏第一个表单并加载第二个表单。当第二个表单完全加载时,它将尝试关闭第一个表单。
Make sure that on your Application Tab under your Project properties the option is set to "When last form closes".
确保在您的项目属性下的应用程序选项卡上,该选项设置为“最后一个表单关闭时”。
回答by Filip
You just need to put Hide() instead of Close :)
你只需要把 Hide() 而不是 Close :)
So for example, in the project im doing right now...
例如,在我现在正在做的项目中......
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click // Button1.Click is your "continue" button
Hide()
LogInFrom.Show()
End Sub