You cant. The Form2 was stared as the Main form in the Main method. You can only Hide it (use this.Hide() method), if you will close it, the whole application will close.
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
There is maybe another solution:
Private Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
' Form1 in this Application.
Application.Run(New Form2())
' Form2 in this application.
End Sub
.. if you want Form2 to open after Form1 exits. There's no going back. When Form2 closes, the programs end.
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
or:
Imports System.Windows.Forms
Imports Microsoft.VisualBasic.ApplicationServices
Namespace WindowsApplication1
Public Class MyApp
Inherits WindowsFormsApplicationBase
Public Sub New()
Me.ShutdownStyle = ShutdownMode.AfterAllFormsClose
Me.MainForm = New Form1()
End Sub
End Class
NotInheritable Class Program
Private Sub New()
End Sub
<STAThread> _
Private Shared Sub Main(args As String())
Dim app As New MyApp()
app.Run(args)
End Sub
End Class
End Namespace
You can now close your startup form (Form1) without problems. Your program will exit when the last form is closed.
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474