1
votes

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 
2
You probably want your Close after the code to show the MainScreen - Matt Wilko
@MattWilko pitty u cant hand out slaps lol one of those momments - csharpdude77
if the second form is frmMainScreen, then when you Close whatever form this code is in, the form goes away along with the code you want to run - Ňɏssa Pøngjǣrdenlarp
Plutonix is right. Use Me.Hide() instead - Arman
you may want the form to have a scope larger than just that click event too, especially if you have code which will reference it - Ňɏssa Pøngjǣrdenlarp

2 Answers

1
votes

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.

1
votes

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.