472,353 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 14713
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tim Gosselin | last post by:
I am writing a tcp tunnel but cannot find a way of detecting when a socket shuts down its read end without writing to the socket. For testing the...
13
by: dave yan | last post by:
hi, i have some forms which use javascript for data validation, e.g., checking to make sure all required fields are completed, checking that...
2
by: Dom Nicholas | last post by:
Hi, My question is this : how do I detect from another window which didn't create a new window whether it exists ? For example, is there a...
8
by: Les Desser | last post by:
Is there any way to detect within A97 when Windows is trying to shut down, so I can close down the application gracefully? We currently have a...
4
by: Chris | last post by:
When a request comes into a page on my ASP.net site and a session is not found, I want to detect whether the request is an initial request or if...
5
by: steve | last post by:
Hi All I have a form set as the splash screen in VB.net 2005 application properties How can I tell when it has or is closing, as I want to then...
2
by: O.B. | last post by:
In the following code snippet, the thread successfully makes it to the line where it waits for data to be received. Then the client closes the...
1
by: wwwords | last post by:
Is there a general method for detecting that a user has changed the record currently visible on a form, whether this is by hitting PgUp or PgDn or...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.