Closing forms

Nicko101

Member
Joined
Aug 31, 2004
Messages
10
Programming Experience
Beginner
How do i close a form so that it cannot be seen or used, all textboxes etc. are returned to their default values and it can be opened with Dim ... As New declaration. I tried this code:

VB.NET:
 Dim form1 As New Form1() 

form1.Show()

Me.Close()
but this only brought up the second form without closing the first. Help please anyone.

Nicko101
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
in a module, Public myform1 as form1

first form:

myform1 = new form1

me.close

that should open a new form and close the currently opened one
 

Lucktas

Member
Joined
Jun 27, 2004
Messages
5
Location
England
Programming Experience
3-5
Or you could use the following code which is similar to what you had:

VB.NET:
 'Specify that form1 is the form to create. 
Dim frm as new form1
'Show the form
frm.show
'Hide the form that launched it
me.visible
Note: this does not acutally close the form but instead it will hide it. The user will not know the difference, but when you close the program it will not longer be there, and to get it back you simply have to change the me.visible parameter to true.
 

Nicko101

Member
Joined
Aug 31, 2004
Messages
10
Programming Experience
Beginner
That might work, but i think i have solved the problem. If i make the second form a dialog box of the first, and set the dialogresult property of one of the buttons, that should work fine for what i need.
 

liam

Member
Joined
Jun 8, 2004
Messages
23
Programming Experience
Beginner
dispose first form...

create a code that will dispose the first form then create a new instance of the form.
 

liam

Member
Joined
Jun 8, 2004
Messages
23
Programming Experience
Beginner
code

If TRANSrem Is Nothing OrElse TRANSrem.IsDisposed Then TRANSrem = New frmTRANSrem

TRANSrem.MdiParent = Me

TRANSrem.Show()
 
Top Bottom