Closing Forms in VB.NET

mainform.hide in VB.net

Page 1 of 1

6 Replies - 122611 Views - Last Post: 19 April 2009 - 05:30 AM Rate Topic: -----

#1 cimpercee  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 127
  • Joined: 10-August 06

Closing Forms in VB.NET

Posted 05 October 2006 - 12:25 PM

Hi guys...I made a project on vb.net.Im working with multiple forms.Now,from the main form, I activated the 2nd form.then hide the main form. My problem is when I directly close the 2nd form, my project is till running.I closed it trough the "Close Button" of the form.Any way i could interact with that so I could go back to the Main(first) form when i close it there.

Thanks :D

This post has been edited by Videege: 05 October 2006 - 01:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Closing Forms in VB.NET

#2 Videege  Icon User is offline

  • rÍvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Re: Closing Forms in VB.NET

Posted 05 October 2006 - 01:14 PM

Not sure if I'm quite getting your question, but here it goes.
If you want your application to exit when form two is closed, simply use your reference to the main form and call Close() on it? Likewise, if you simply want to show form one when form 2 is closed, just call Show().

If this is not what you want..check out this article and scroll down to method 7, I think that might be what you're getting at.

Hope this helps :D.
Was This Post Helpful? 0
  • +
  • -

#3 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 445
  • View blog
  • Posts: 3,084
  • Joined: 18-September 06

Re: Closing Forms in VB.NET

Posted 06 October 2006 - 01:40 AM

As Videege says, you'll need to use either the Close() method or the Show() method.

If you want to close Form1 when you close Form2, in the close button sub where you close the second form, ad the line:

Form1.Close()

Similarly, if you want to return to Form1, add this line instead:

Form1.Show()

Obviously, you will need to change Form1 to the name of your main form. :D
Was This Post Helpful? 0
  • +
  • -

#4 cimpercee  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 127
  • Joined: 10-August 06

Re: Closing Forms in VB.NET

Posted 07 October 2006 - 01:01 AM

View PostBort, on 6 Oct, 2006 - 01:40 AM, said:

As Videege says, you'll need to use either the Close() method or the Show() method.

If you want to close Form1 when you close Form2, in the close button sub where you close the second form, ad the line:

Form1.Close()

Similarly, if you want to return to Form1, add this line instead:

Form1.Show()

Obviously, you will need to change Form1 to the name of your main form. :D


its not the close button(command button) of the second form but the close button on the on the upper right top corner of the form beside the maximize.

im not sure if i explain myself clearer here but i wish you could help me :crazy:
Was This Post Helpful? 0
  • +
  • -

#5 ersanjana  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-September 06

Re: Closing Forms in VB.NET

Posted 07 October 2006 - 01:16 AM

View Postcimpercee, on 5 Oct, 2006 - 12:25 PM, said:

Hi guys...I made a project on vb.net.Im working with multiple forms.Now,from the main form, I activated the 2nd form.then hide the main form. My problem is when I directly close the 2nd form, my project is till running.I closed it trough the "Close Button" of the form.Any way i could interact with that so I could go back to the Main(first) form when i close it there.

Thanks :D



fist of all u have to create a object of your form1 say it is f1 in second form say it is form2
code in form2 is:
dim f1 as new form1

then if u want to close form1 when u close the form2 then simply write
form2.close()
f1.close()

and if u want to display the form1 when u close the form2 then
form2.close()
f1.focus()
Was This Post Helpful? 0
  • +
  • -

#6 cimpercee  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 127
  • Joined: 10-August 06

Re: Closing Forms in VB.NET

Posted 08 October 2006 - 07:34 AM

View PostVideege, on 5 Oct, 2006 - 01:14 PM, said:

Not sure if I'm quite getting your question, but here it goes.
If you want your application to exit when form two is closed, simply use your reference to the main form and call Close() on it? Likewise, if you simply want to show form one when form 2 is closed, just call Show().

If this is not what you want..check out this article and scroll down to method 7, I think that might be what you're getting at.

Hope this helps :D.


that article is nice..thanks
Was This Post Helpful? 0
  • +
  • -

#7 N(s@r  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-April 09

Re: Closing Forms in VB.NET

Posted 19 April 2009 - 05:30 AM

Hello! cimpercee :)

Here's an easy and practical solution to fix your problem. At first create an instance of form2 in form1 and make form1 as the owner of form2. Hide Form1 and Show Form2. On Form2 Cancel the default Closing Event, add a new Sub which will enable Closing Event and Close the owner.


'''Code Form1
		Dim form2 As New Form2
		form2.Owner = Me
		Me.Hide()
		form2.Show()

'''Code Form2
Private Sub Form2_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
		e.Cancel = True
		Close_Owner(e)
	End Sub

	Private Sub Close_Owner(ByVal e As System.Windows.Forms.FormClosingEventArgs)
		e.Cancel = False
		Me.Owner.Close()
	End Sub


For more info visit my blog

This post has been edited by N(s@r: 19 April 2009 - 05:33 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1