Closed event not occuring

  • Thread starter Thread starter Lee Silver
  • Start date Start date
L

Lee Silver

Given a form f1 with a control c1.

The control's Click event contains:

Me.Hide

The proc that accesses the form contains:

f1.ShowDialog

Immediately after ShowDialog is invoked the form's Load event occurs, as
expected. Immediately prior to ShowDialog returning, the form's Closing event
fires, as expected, which I thought would be followed by the Closed event, but
it wasn't-- it never occurred. I tried to force it to occur by adding f1.Close,
f1.Dispose and f1=Nothing after the ShowDialog; all to no avail -- nothing I did
caused the Closed event to occur.

But adding:

Me.Close

after the Me.Hide in the Click event yielded the expected behavior.

This seems like the wrong solution. What am I doing wrong / misunderstanding?

--
// Lee Silver
// Information Concepts Inc.
// http://www.information-concepts.com

Facilitating the automated conversion of Data into Information
since 1982
 
Herfried:
Hiding a form instance doesn't close it. Call its Close method instead.

According to the docs at the topic labelled "Displaying Modal and Modeless
Forms" I quote the following:

"Note If a form is displayed as modal, the code following the ShowDialog method
is not executed until the dialog box is closed."

When the Me.Hide is executed and there is no Me.Close, as I originally
indicated, execution goes to the Closing event and then ShowDialog returns.

According to the docs, at that point the form is closed, but if so, why hasn't
the Closed event occured? If the docs are wrong and I need to explicitly close
the form to trigger the Closed event, so be it, but I'd like someone to confirm
that.

--
// Lee Silver
// Information Concepts Inc.
// http://www.information-concepts.com

Facilitating the automated conversion of Data into Information
since 1982
 
Yes, this seems to be a problem in WinForm. I'm reporting it back to
WinForm team.

To workaround this problem, you can call Form.Close instead.

Regards,
Xin

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. (c) 2003 Microsoft Corporation. All
rights reserved.
 
Back
Top