closing one form from another

G

Guest

I have a startup form called frmStartup. It runs code and then calls another frmApp. I will never return to the frmStartup. I use the following code to exit the entire application fom within frmApp

Private Sub frmHorizontal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPres

If e.KeyChar = Microsoft.VisualBasic.ChrW(122) The
'Dim frmStartup As New Startu
'frmStartup.Close(
Me.Close(
End I

End Su

As you can see, I have tried a few things to get the frmStartup to close when the frmApp closes but haven't had any luck yet. I could also close frmStartup when I load frmApp but since the code is probably identical I haven't got that to work either. What am I missing here. This has to be simple. I don't understand why if I uncomment the two lines above, it doesn't work

Any ideas
John
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?amNyb3VzZQ==?= said:
I have a startup form called frmStartup. It runs code and then calls
another frmApp. I will never return to the frmStartup. I use the
following code to exit the entire application fom within frmApp:
Private Sub frmHorizontal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

If e.KeyChar = Microsoft.VisualBasic.ChrW(122) Then
'Dim frmStartup As New Startup
'frmStartup.Close()
Me.Close()
End If

End Sub

As you can see, I have tried a few things to get the frmStartup to
close when the frmApp closes but haven't had any luck yet.

Ypu will have to make a reference to your instance of 'frmStartup'
available to the other form, for example, by adding a property that
points to the main form.
 

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

Top