How do i unload a form without closing the whole application

jamose

Member
Joined
Feb 3, 2006
Messages
8
Programming Experience
1-3
i have a small problem. I have an application that has several forms. Sort of like a questionnaire. So one form has a button called next to call the next form. This works well but how do i unload the complete form before moving to the next form.
(me.close) exits the whole application
 
Last edited:
You can hide it (Me.Hide), then display next (frmNext.Show), then close it (Me.Close).
 
Apparently, hiding the form then loading the next form and closing the hidden form exits the whole application. This is the information that is displayed in the debug window.

'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded.
'WinApp': Loaded 'C:\Documents and Settings\Administrator\My Documents\WinApp\WinApp\bin\WinApp.exe', Symbols loaded.
'WinApp.exe': Loaded 'c:\windows\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll', No symbols loaded.
'WinApp.exe': Loaded 'c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', No symbols loaded.
'WinApp.exe': Loaded 'c:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll', No symbols loaded.
'WinApp.exe': Loaded 'c:\windows\assembly\gac\microsoft.visualbasic\7.0.5000.0__b03f5f7f11d50a3a\microsoft.visualbasic.dll', No symbols loaded.
The program '[2404] WinApp.exe' has exited with code 0 (0x0).

Could someone please explain to me what the error might be.
 
The ability to do this is built into the 2005 IDE but it's a pain in the behind in 2003. If you have a form as the startup object for a project then as soon as that form closes so does your app, period. If you want different behaviour then you must use a Main method. Even then it can be tricky, depending on what you want. As long as you don't need to go backwards at any point you can do something like this:
VB.NET:
Public Sub Main()
    Application.Run(New Form1)
    Application.Run(New Form2)
    Application.Run(New Form3)
End Sub
This will open an instance of Form1, then when that closes it will open an instance of Form2, then when that closes it will open an instance of Form3, then when that closes the app will exit.
 
Some more great knowledge. I watch your posts and replies b/c I learn alot from reading after you. You seem like a good programmer with lots of knowledge. Thanks
 
Oops, that's right, I answered kinda in 'VB 2005 mode' :) In VB 2005 you can go to application settings and choose Shutdown Mode when startup form closes or when last form closes.. (a side note: wasn't this standard behaviour in VB6, or do I remember wrong?)
 
Back
Top