Open a new form and close the previous form.

S

Scott H.

In VB6 if you wanted to unload form1 and then load form2, the code would be:

Sub Button_Click
Form1.Visible = False
Unload Form1

Load Form2
Form2.Visible = Ture
End Sub

How is this done in VB.NET?

Thanks.
 
J

Joe Cool

In VB6 if you wanted to unload form1 and then load form2, the code would be:

Sub Button_Click
 Form1.Visible = False
 Unload Form1

 Load Form2
 Form2.Visible = Ture
End Sub

How is this done in VB.NET?

Thanks.

There are several ways to accomplish this, it depends on exactly what
you want to do. Typically, you would unload a form in VB6 if you
didn't need to show it anymore.

In .NET a form is loaded when you invoke the Show or ShowDialog
method. It is unloaded when you invoke the Close method. But you can
leave the form loaded but make it not visible by either setting the
Visible property to false or the Opacity property to 0.

The Show method shows the form non-modal. SHowDialog shows it modally.
Typically, when a form is shown with the ShowDialog, the form is
closed by invoking the Close method itself. If shown non-modally, then
the thread that Showed it typically Closes it.
 
S

Scott H.

I was able to get this to work:

Sub Button_Click

me.Hide
Dim Frm2 as New Form2
Frm2.show

End Sub

And then to display Fom1 from Form2:

Sub Button_Click

Me.Close
Form1.Visible = True

End Sub


I was concerned about just hiding Form1 and not disposing it or in VB6
terms, unloading it. So the above approach is considered an acceptable
practice?

Thanks for your help.
 

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

Similar Threads


Top