473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 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 14824
"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 write end of the remote endpoint I just do a: if...
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 data falls within valid ranges for certain fields,...
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 window-id's container of some sort that hangs around...
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 trap in the main menu asking the user to confirm if...
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 the user did have a session going that has now been...
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 run some licence checking code without the...
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 connection. The thread wakes up and returns from 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 clicking on a navigation button, even if no change...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.