Home All Groups Group Topic Archive Search About

how to activated a closed form?

Author
25 May 2005 9:54 PM
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!

Author
25 May 2005 10:28 PM
AinO
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).

Show quoteHide quote
"ywchan" <ywc***@gmail.com> wrote in message
news:eyUshRXYFHA.3164@TK2MSFTNGP12.phx.gbl...
> 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!
>
>
Are all your drivers up to date? click for free checkup

Author
25 May 2005 10:33 PM
John B
ywchan wrote:
Show quoteHide quote
> 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();
                }

Bookmark and Share