Close & Load Form

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
In FormClosing event of my 1st form, I show the 2nd form like this:
Visual Basic:
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim F As New Form2
        F.ShowDialog()
    End Sub
But the problem is that Form1 waits for Form2 to be closed and then it closes!
How should I let's Form1 to completely unload and then load the Form2?
Thanks :)
 
I'm guessing that Form1 might be the application's main form. If this is the case, then F.Show() won't work. (Hence the ShowDialog?)

If I'm right then there is a right way to approach the situation, and "the other way."

What you should probably do is write a custom Main() for your program. How this is done might vary from version to version with VB (I haven't used newer versions). You would also need to inherit the ApplicationContext class and write your own custom ApplicationContext that manages your forms for you.

The "other way" is to simply hide your Form1 before showing Form2, but this prevents resources from being released in a timely fasion and is not the preferred technique.
 
Have you explored the MDI option? Most issues I have encountered that needs one form to open a second form is when there are just too many controls to display on one form. MDI (Multiple Document Interface) or maybe Tabs are options that can be considered.

my 2 cents.
 
i put an example in the codebank over 2 years ago of being able to close the main form that loads without shutting the app down, the vbcode looks a bit screwed up because of messed up colour tags, but here's the link
a readable code is found on an external link to vbforums here
a very basic source example is included.

regards.
 
Back
Top