Correct way of reusing dialog forms?

  • Thread starter Thread starter Peter B
  • Start date Start date
P

Peter B

When I create a new instance of a dialog form, will it use the old form if
it still is in memory? Is there another way of "reusing" the form?

I.e.
In mainForm:
dForm = new DForm();
dForm.ShowDialog();

When closing in dialog form:
this.DialogResult = DialogResult.OK;
this.Close();

thanks,

Peter
 
Hmm, I think I need to re-formulate my question.

In the main form, where I create the instance of the dialog form, how do I
check if it has already been created earlier? Doing
dForm = new DForm();
dForm.ShowDialog();
each time I want the form shown is not very "reusing" is it? Or is the
runtime so smart that it reuses the form although I call "new"?

Then to follow up the first question, if calling "new" actually creates a
new instance (which it sounds like it does:) ), how do I check if the form
has already been created? Is this the correct way?
if( dForm == null )
dForm = new DForm();
dForm.ShowDialog();

I am probable confusing the Show forms with the ShowDialog forms here, but I
am sure I get a ObjectDisposedException when using this kind of technique...

thanks,

Peter
 
Back
Top