14

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! :)

BaeFell
  • 640
  • 1
  • 8
  • 28
  • 4
    Try putting `Me.Close` after `Login.Show()`. Also, make sure your Welcome form isn't your main form ... – Alex Aug 28 '13 at 14:57
  • 1
    Try taking a look at this http://stackoverflow.com/questions/17927615/when-my-form-is-hidden-and-reloaded-from-another-form-it-is-not-executing-the-co – Manny265 Aug 28 '13 at 16:30

8 Answers8

23

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"

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
9

show the form before the close.

Dim Login As New Form
Login.Show()
Me.Close()
Markjw2
  • 151
  • 6
5

Better is if you use Me.Hide()

Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
Zigab123
  • 51
  • 1
  • 1
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.

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
2

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()
Alex
  • 4,821
  • 16
  • 65
  • 106
0

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".

Lucas Zamboulis
  • 2,494
  • 5
  • 24
  • 27
0

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.

Daniel
  • 1
-2

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
Filip
  • 1