Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a form from a another form

Status
Not open for further replies.

rushdib

Programmer
Jun 12, 2001
203
US
Hi,
How do I close a form from another form? Is this possible in VB.Net without using MDI?

Thank You,

Rushdi
 
Just use the objRef.Close method where objRef holds a reference to the instance of the form to be closed. If it is the startup form, the entire application will close. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Like John says...

First step is to get (or already have) a reference to the other form (this is where most people have problems).

Second step is to call the Close method on it.

Chip H.
 
Hi,
I am getting an object reference error when I tried the following code:

In Form 2:

dim refForm1 as Form1

refForm1.Close

If I do this

dim refForm1 as new Form1

refForm1.Close

I don't get an error, but that's a new object so it won't close the form I wanted to.
Now I am opening Form2 from Form1, is that going to be a problem closing the Form1?

Thanks,

Rushdi
 
Where is the varaiable holding the reference to the form you created? That is the variable you must use to Close the instance of the form.

If you are working on a project that was upgraded from VB6 by the VB.Net Upgrade Wizard, then you get the reference from the Shared method formname.DefInstance, I think. I got rid of all that code after changing my code to explicitly create each instance of the form and use an object variable to hold the reference. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top