Hi all,

I have created two forms namely form1 and form2 in my application. I
created a button "start" in form1. When this button is clicked form2
is initialised as a child object and an instance of form2 is displayed
at the same time hiding form1 from the user. In form2 I have an "exit"
button, which when clicked invokes "me.close()". This closes form2
which is active. but still the program is not stopped, Because form1
was the startup object and it is been hidden. So the hidden form1 is
alive and hence the program does not stop and the user is not seeing
anything on his screen.Please tell me a way to hide form1 when form2
is invoked and at the same time when form2 is closed the entire
program should be closed.

With smiles,
Deepa.

Re: accessing form controls in Vb.net by Imran

Imran
Tue Oct 19 13:34:42 CDT 2004

One option is to call Application.Exit in the Closed event of Form2 - but
thats more of a forced shutdown than an elegant one. The other option is to
pass a reference of Form1 to the constructor of Form2 and then in the Closed
event of Form2, call the Close method of Form1. Here's how:

' Form1 Code
Private Sub btnStart_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnStart.Click
Dim frm2 As New Form2(Me)
Me.Hide()
frm2.Show()
End Sub

' Form2 Code
Private frm1 As Form1

' note the changed constructor of Form2
Public Sub New(ByVal frm As Form1)
MyBase.New()
frm1 = frm
'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub

Private Sub Form2_Closed(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Closed
frm1.Close()
End Sub


That should pretty much do it..

hope that helps..
Imran.


"Deepa Yamini S" <sdeepayamini@yahoo.co.in> wrote in message
news:26bed73a.0410191010.20f734d8@posting.google.com...
> Hi all,
>
> I have created two forms namely form1 and form2 in my application. I
> created a button "start" in form1. When this button is clicked form2
> is initialised as a child object and an instance of form2 is displayed
> at the same time hiding form1 from the user. In form2 I have an "exit"
> button, which when clicked invokes "me.close()". This closes form2
> which is active. but still the program is not stopped, Because form1
> was the startup object and it is been hidden. So the hidden form1 is
> alive and hence the program does not stop and the user is not seeing
> anything on his screen.Please tell me a way to hide form1 when form2
> is invoked and at the same time when form2 is closed the entire
> program should be closed.
>
> With smiles,
> Deepa.