Q: Closing a form

  • Thread starter Thread starter Geoff Jones
  • Start date Start date
G

Geoff Jones

Hiya

Supposing a form has been created as follows:

Dim form1 As New Form

How can I check to see if the form has been closed i.e. by clicking on the
cross in the top right of the form.

I'm guessing here, but it has been closed, the variable form1 won't "point"
to anything. Can I use this to see if the form has been closed?

Any example code would be most useful.

Geoff
 
Geoff,

Geoff Jones said:
Supposing a form has been created as follows:

Dim form1 As New Form

How can I check to see if the form has been closed i.e. by clicking on the
cross in the top right of the form.

I'm guessing here, but it has been closed, the variable form1 won't
"point" to anything. Can I use this to see if the form has been closed?

The variable will still point to the form's instance, but the instance might
be disposed.

If the form is shown modally:

\\\
Dim f As New FooForm()
f.ShowDialog()
MsgBox("The form has been closed!")
///

Otherwise:

\\\
Dim f As New FooForm()
f.Show()
..
..
..
If f.IsDisposed Then
MsgBox("The form has been closed!")
Else
MsgBox("Form still open!")
End If
///

In addition to that, you can use 'AddHandler' to add a handler to a form's
'Closed' event in order to be notified when a form closes.
 

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

Similar Threads


Back
Top