Switch between two Forms

  • Thread starter Thread starter Yavuz Bogazci
  • Start date Start date
Y

Yavuz Bogazci

Hi,

i have the following problem:

In VB6 i switched between two forms on this way:

FORM1:
sub onButton_Click
form2.show
me.close
end sub

FORM2:

sub onButton_Click
form1.show
me.close
end sub


How can i realize this with VB.Net? When i want to show
form2 with

form2.show()
me.close()

the hole Application terminates! What must i do?

Thank you
Yavuz Bogazci
 
The Code looks exactly:

Dim form As New form2
form.Show()
Me.Hide()

yavuz bogazci
 
Hi,
You cannot close the startup object.

see if hiding and unhiding solves your problem

Cheers
Benny
 
Yavuz Bogazci said:
Hi,

i have the following problem:

In VB6 i switched between two forms on this way:

FORM1:
sub onButton_Click
form2.show
me.close
end sub

FORM2:

sub onButton_Click
form1.show
me.close
end sub


How can i realize this with VB.Net? When i want to show
form2 with

form2.show()
me.close()

the hole Application terminates! What must i do?

All applications have a start prozedur. It is called "Main". As soon as Sub
Main (and all other threads) exits, the application is terminated. In the
project properties you can either select a Sub Main, or a startup Form. If
you choose a startup Form, VB.NET creates an invisible Sub Main. For
example, if you choose Form1 as the startup Form, the following Sub Main is
created within Form1:

Shared Sub Main
Application.Run(New Form1)
End Sub

Application.Run contains a loop that processes the messages (e.g. mouse or
keyboard input messages) that Windows sents to the application.
Application.Run exits when Form1 is closed. Consequently, the application
quits because the end of Sub Main is reached.

In your application, you do not have a Form that is always visible and can
therefore be set as the startup object. So, you have to create your own Sub
Main:

Shared Sub Main
Dim F As New Form1
F.Show
Application.Run()
End Sub

Now the application does not quit whenever Form1 is closed. Your code should
work now, but you have to close the application on your own by calling
Application.ExitThread after closing all open Forms.
 
Back
Top