问题
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! :)
回答1:
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
find : "Shutdown Mode"
Change from
"When startup form closes" --> "When last form closes"
回答2:
show the form before the close.
Dim Login As New Form
Login.Show()
Me.Close()
回答3:
Better is if you use Me.Hide()
回答4:
There is a shutdown mode project 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.
回答5:
If your Welcome Form isn't your main form, you just need to put your Me.Close
after your Login.Show()
Dim Login As New Form
Login.Show()
Me.Close()
回答6:
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".
回答7:
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.
回答8:
You just need to put Hide() instead of 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
来源:https://stackoverflow.com/questions/18491429/how-to-open-a-new-form-but-closing-the-old-one-in-vb