Form dispose hides the main form

W

Wolfgang Link

hi group,

my problem:

Form1 load Form2.
Closing Form2 with dispose
Now the form1 is hidden ??

Here is a test code:

Form1 (only one button):
-------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim fChildForm As New Form2
fChildForm.ShowDialog()
End Sub


Form2 (only one button):
------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CloseForm(Me)
End Sub


Module1:
-----------------------------
Module Module1
Public Sub CloseForm(ByVal frm As Form2)

frm.Close()
frm.Dispose() '// memory free

End Sub
End Module

Any ideas ?

greetings from germany

Wolfgang
 
S

Simon Hart

You are effectively disposing your form before you have actually closed it.
You should implement IDisposable then wrap the button1 method in a using
statement IE:

using (Form2 fChildForm = new Form2())
{
fChildForm.ShowDialog();
}

Or call the dispose on return to Form1.

Sorry for C#, my VB is a little rusty.

Simon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top