Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In FormClosing event of my 1st form, I show the 2nd form like this:

   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 :)

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted

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.

  • Leaders
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...