how to activated a closed form?

  • Thread starter Thread starter ywchan
  • Start date Start date
Y

ywchan

when i press a button, a form.Show is triggered
the form provides some reference information for me to input information in
the parent form, so i don't want to use ShowDialog.
besides, i want the form to opened once only

how can i do this?

i use
form1 frmReference;
if (frmReference == null)
{
frmReference = new form1();
}
frmReference.Show();

I can successfully control a form to be opened once only
but when i close the form, and press the button again...
there is error encountered....

thanks!
 
My guess, without checking (late, lazy, sorry), and assuming frmReference is
global, is that
the form is disposed whilst closing so you have a reference in your parent
wich is not null but
the child form is gone (handles freed, memory in garbage, etc ...).

Why not pass a parent reference to the child form and when the child closes
down it notifies its parent of
it's closure, where the parent resets the child reference to null (so it can
be reconstructed with your button
click) ?

AinO.

PS. Specifying the error message does wonders (i was not very specific
myself, i know so 1-1).
 
ywchan said:
when i press a button, a form.Show is triggered
the form provides some reference information for me to input information in
the parent form, so i don't want to use ShowDialog.
besides, i want the form to opened once only

how can i do this?

i use
form1 frmReference;
if (frmReference == null)
{
frmReference = new form1();
}
frmReference.Show();

I can successfully control a form to be opened once only
but when i close the form, and press the button again...
there is error encountered....

thanks!
Handle the disposed event of your form and set your reference to null in
this event.

Cheers
JB


if(PropertiesForm == null)
{
PropertiesForm = new frmProperties();
PropertiesForm.Disposed += new EventHandler(PropertiesForm_Disposed);
}
if(!PropertiesForm.Visible)
{
PropertiesForm.Show();
}
 
Back
Top