dotnetdevcsharp
dotnetdevcsharp

Reputation: 3980

VB.NET - Why is the secondary form closing?

In vb.net, whenever I click my button "ok", it also closes the second form? And please slap me if I have done a school boy error here. I just do not understand what is going on.

 Private Sub btOk_Click(sender As System.Object, e As System.EventArgs) Handles btOk.Click
       Close()
        Dim frmMainScreen As New frmMain

        frmMainScreen.Show()
 end sub 

Upvotes: 1

Views: 96

Answers (2)

Deja Vu
Deja Vu

Reputation: 413

I agree with @Alex you have to change the project properties (Application Tab => Shutdown mode => Select: "When last form closes") first, but also you need to change your code to be:

 Private Sub btOk_Click(sender As System.Object, e As System.EventArgs) Handles btOk.Click
        Dim frmMainScreen As New frmMain
        frmMainScreen.Show()
        Close()
 End Sub

Show the second form then close the previous one.

Upvotes: 1

rewewrqfdefwds
rewewrqfdefwds

Reputation: 301

You first have to show the new form, and then have to close the old form.

Default settings in your application is closing when last form closed. So if you close the actual form (which is the last i think) then your application closes complete.

Upvotes: 1

Related Questions