Events fired when Form.ShowDialog is called

G

Guest

Hello everybody,

The MSDN says about ShowDialog that

"When a form is displayed as a modal dialog box, clicking the Close button
(the button with an X at the upper-right corner of the form) causes the form
to be hidden and the DialogResult property to be set to DialogResult.Cancel.
Unlike modeless forms, the Close method is not called by the .NET Framework
when the user clicks the close form button of a dialog box or sets the value
of the DialogResult property. Instead the form is hidden and can be shown
again without creating a new instance of the dialog box. Because a form
displayed as a dialog box is not closed, you must call the Dispose method of
the form when the form is no longer needed by your application."

The way I understand this is that even if I re-instantiate the class that
implements my form, the framework will reuse some previously created
structures and that's how I would explain why the Load event is not fired for
subsequent calls to ShowDialog.

So here is my question: What is the pattern I need to use to display one
form over and over and make sure that all internal controls are initialized
to proper values every time the form is shown? What is the event that's fired
every time ShowDialog is called, if there is such an event? If not, how else
should I approach this?

TIA,
Eddie
 
G

gourmete

Hi!

Why don´t you dispose the form after showing?
If you want to recall the initialization code anytime the form is
shown, i think it would not be an performance leak to create it
completly new?!?
Perhaps you should call GC.Collect() after Diposing to be sure that
there is really nothing left...
 

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

Top