How to open a new form but closing the old one in VB
Asked Answered
N

8

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

Nurseryman answered 28/8, 2013 at 14:56 Comment(2)
Try putting Me.Close after Login.Show(). Also, make sure your Welcome form isn't your main form ...Oke
Try taking a look at this #17928115Quagmire
O
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"

Optics answered 28/8, 2013 at 14:59 Comment(4)
Can't seem to find itNurseryman
Check this:- msdn.microsoft.com/en-us/library/…Optics
You can go to the properties of your project and there you have to select this!!!Optics
Thanks! It works now :) Im only 15 :P Learnt some VB in school as part of my GCSE course and now im going to well ahead of the class ;)Nurseryman
R
9

show the form before the close.

Dim Login As New Form
Login.Show()
Me.Close()
Rightwards answered 28/8, 2013 at 14:58 Comment(1)
Does the same thing, just closes the whole thing.Nurseryman
I
5

Better is if you use Me.Hide()

Irrelevant answered 22/12, 2013 at 9:20 Comment(0)
E
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.

Evangelize answered 28/8, 2013 at 15:0 Comment(0)
O
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()
Oke answered 28/8, 2013 at 15:0 Comment(0)
H
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".

Hydrolytic answered 21/3, 2014 at 2:57 Comment(0)
C
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.

Constitutive answered 7/12, 2014 at 4:53 Comment(0)
B
-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
Betwixt answered 4/12, 2014 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.