I have 2 forms right now Form1 and Form2 the default setting start up is Form2. Inside Form 2 there was a button that will release the Form1 button using Form1.Show().

I have now the problem. What I want to do now is to close the Form2 without closing the Form1.

inside Form2 button:

End sub

is there any way that solves my problem?

Recommended Answers

All 4 Replies

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.

here is a picture can help you

There is maybe another solution:

Private Shared Sub Main()
	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.


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()
		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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.