Unload a Form

  • Thread starter Thread starter V.Boomessh
  • Start date Start date
V

V.Boomessh

Hai
can any one help me on this problem.

I am new to VB.NET.

I have 2 forms. (form1 and form2)

On click of a button in form1 i want to show form2 and
unload form1

how can i accomplish it.

V.Boomessh
 
As far as I know, when you call the close method of a form, it is unloaded.
So, you would have something like the following:

'Create an instance of the second form
Dim MySecondForm As New Form2

'Close (unload) this form
Me.Close()

'Show the second form
MySecondForm.Show()


Hope this helps,

Mun
 
Hai,

The code just ends the application and comes out. It is
not solving the problem.

regards,
V.Boomessh
 
Hi V Boomessh,

For this kind of problems is a active newsgroup
Microsoft.public.dotnet.languages.vb
There you can get a lot of answers on this kind of problems.

One of the answers can be.
Assuming you use the form2 as a kind of dialog than the most simple is
\\\
dim frm as new form2
me.hide
frm.showdialog
me.show
frm.dispose
///
I hope this helps,

Cor
 
If the first form is your main form, unloading it will terminate your
application. So, what you need to do, is just hide this form, and then
unload it when you close the second form.

Eg.

'Create a new instance of the second form
Dim MySecondForm As New Form2

'Set the form owner
MySecondForm.Owner = Me

'Hide this form
Me.Hide()

'Show the second form
MySecondForm.Show()


In the Form2_Closed event, you could have the following:

'Unload the main form
Me.Owner.Close()


This appears to work in a small test project I created, but I'm not sure if
this is the correct practice. I hope someone else can confirm this is
correct, or offer the correct way of doing this :-)

Cheers,

Mun
 
Back
Top