954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to show the form that closes the previous form?

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:

Button_Click....
Form1.Show()
'End
End sub

is there any way that solves my problem?

masterjiraya
Junior Poster
153 posts since Jul 2008
Reputation Points: 10
Solved Threads: 4
 

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
 

here is a picture can help you

Attachments 7-4-2011_1-56-45_PM.png 68.06KB
Fa3hed
Newbie Poster
17 posts since Jun 2011
Reputation Points: 10
Solved Threads: 3
 

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
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: