469,306 Members | 1,565 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Detecting whether a form has been closed or not

How do you detect whether a form has been closed or not?
Thanks.

--
Xero

http://www.chezjeff.net
My personal web portal
Nov 21 '05 #1
7 14482
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> schrieb:
How do you detect whether a form has been closed or not?


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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Herfried,

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


It is right before you understand me wrong.
However I had to look twice.

:-)

Cor
Nov 21 '05 #3
Hi Herifried,

Thanks for replying. I found the information in my previous post wasn't
enough to tell you the entire picture ... so I think I should tell you a
little bit more about what I'm trying to do.

There are two forms in my program - namely Form 1 and Form 2. A button in
Form 1 opens Form 2, where the user is prompted to enter some information.
After the information has been entered, Form 2 is closed and the data
collected in Form 2 is used for some process in Form 1.

I'd like to know how can Form 1 detect that Form 2 has closed and it can
carry on.

Thanks again.

Xero
"Herfried K. Wagner [MVP]" wrote:
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> schrieb:
How do you detect whether a form has been closed or not?


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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> schrieb:
There are two forms in my program - namely Form 1 and Form 2. A button in
Form 1 opens Form 2, where the user is prompted to enter some information.
After the information has been entered, Form 2 is closed and the data
collected in Form 2 is used for some process in Form 1.

I'd like to know how can Form 1 detect that Form 2 has closed and it can
carry on.


\\\
Dim f As New DataEntryForm()
If f.ShowDialog() = DialogResult.OK Then
UserName = f.UserNameTextBox.Text
...
End If
f.Dispose()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
I tried but the code didn't work.
I inserted a breakpoint at the line where the 'Dim' statement occured.
In the debugging mode, I highlighted the 'DialogResult' statement to check
its value. 'None' appeared in a tooltip and the program skips the If block.
It seems that the program can't receive the input. How can I fix this?

Thanks.

Xero
"Herfried K. Wagner [MVP]" wrote:
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> schrieb:
There are two forms in my program - namely Form 1 and Form 2. A button in
Form 1 opens Form 2, where the user is prompted to enter some information.
After the information has been entered, Form 2 is closed and the data
collected in Form 2 is used for some process in Form 1.

I'd like to know how can Form 1 detect that Form 2 has closed and it can
carry on.


\\\
Dim f As New DataEntryForm()
If f.ShowDialog() = DialogResult.OK Then
UserName = f.UserNameTextBox.Text
...
End If
f.Dispose()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
Xero,

You would have to tell if you use the showdialog or the show.

Herfried showed two samples.

When a form is showed with showdialog, than the mainform stops and wait
until the showdialog form is closed. And therefore those forms are forever
closed when they come back (not disposed)

When a form is showed with show than the mainform proceeds direct when that
is done.

You know nothing about the showed forms from inside your form where you
started the show, when you don't test that. While there is a slight time cap
between the closed state and disposed state from those forms when the user
has pushed the close button and the actions are done for that.

That can be tested with the second snippet in Herfried first answer to you.

I hope this helps?

Cor
Nov 21 '05 #7
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> schrieb:
I inserted a breakpoint at the line where the 'Dim' statement occured.
In the debugging mode, I highlighted the 'DialogResult' statement to check
its value. 'None' appeared in a tooltip and the program skips the If
block.
It seems that the program can't receive the input. How can I fix this?


Add an "OK" button to the form and assign it to the form's 'AcceptButton'
property. Alternatively you can set the form's 'DialogResult' property to
'DialogResult.OK' in a button's 'Click' event handler prior to closing the
form.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tim Gosselin | last post: by
13 posts views Thread by dave yan | last post: by
2 posts views Thread by Dom Nicholas | last post: by
4 posts views Thread by Chris | last post: by
1 post views Thread by wwwords | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.