Hi Gary,
Based on experience, windows application will run the Form1(the form
created when you create a windows application) as the main form
When the Form1 closed, ExitThread will be called to clean up the
application. So when you call the form1.close, the application will exit.
If you want to simulate the behavior of VB6, you may try to code below.
Right click on the project in the Solution explorer, and select properties.
Navigate to Common properties/General/Startup Object, set the value to Sub
Main.
Add a module to the project, copy and paste the code[Module1.vb] below to
the module.
Press F5 to run the application too see if this does the job for you.
[Module1.vb]
Imports System.Windows.Forms
Public Module MyApplication
Public formCount As Integer
Public fm1 As Form1
Public fm2 As Form2
Public Sub OnFormClosed(ByVal sender As Object, ByVal e As EventArgs)
formCount = formCount - 1
If (formCount = 0) Then
Application.ExitThread()
End If
End Sub
Public Sub Main()
formCount = 0
fm1 = New Form1
formCount = formCount + 1
fm2 = New Form2
formCount = formCount + 1
AddHandler fm1.Closed, AddressOf OnFormClosed
AddHandler fm2.Closed, AddressOf OnFormClosed
fm1.Show()
Application.Run()
End Sub
End Module
[Form1.vb]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
fm2.Show()
'Close form1 and show form2
End Sub
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure!
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.