Re: How to know if a "Form" is currently running in background ? by ppcdev
ppcdev
Tue Jan 27 04:23:45 CST 2004
Thank you very much for your explanations, Mister Hundred ;)
Have to experience C# a little more since now :))))
See ya
"100" <100@100.com> wrote in message news:<uaOgewB5DHA.504@TK2MSFTNGP11.phx.gbl>...
> Hi ppcdev,
> Testing for null won't give you correct results. It will allways be not null
> because you keep reference to the form all the time.
> Whether you have to check the form depends on what you do when you switch to
> the second form. If you call close that will dispose the form and you cannot
> use Show method you have to instantiate a new one. If you use Hide, though,
> you don't have to create the form again you can use Show to show it again.
> If you don't use Close and you keep a reference to the form all the time
> (and obviously you do) you don't have to worry about the form it won't
> dispose itself.
>
> However to check whether the form is ok to be shown you can check Disposing
> and IsDisposed form's proerties. If one of them is true you have to
> instantiate a new form.
>
> HTH
> B\rgds
> 100
>
> "ppcdev" <ppcdev@hotmail.com> wrote in message
> news:2fa5f3a9.0401260523.77c1d7ab@posting.google.com...
> > Hi.
> >
> > Actually, i'm working on C# projects in some french companies.
> > Would anyone know how to know if a "form" is currently running in
> > background ?
> > Actually, I've implemented the following test in an application :
> >
> >
> > Form myFormHandle = new Form1();
> > this.mySavedForm1 = myFormHandle;
> > Form myFormHandle2 = new Form2();
> > this.mySavedForm2 = myFormHandle2;
> > public Form mySavedForm1;
> > public Form mySavedForm3;
> > ...doing many many processes...
> > ...then switch to form2 (eg: Form2.Show());
> >
> >
> > When I need to go back to Form1 from Form2, here's how I think :
> >
> > "Ok, starting point = I'm on Form2"
> > "Is Form1 already existing ?"
> > "If yes, just show it"
> > "If not, recreate it"
> >
> > Here's how I translate this into the computer world :
> > (I'm on Form2)
> >
> > if (Form1.mySavedForm1!=null) Form1.mySavedForm1.Show()
> > else
> > Form1 form1 = new Form1();
> > form1.mySaveForm1 = form1;
> > form1.mySavedForm1.Show();
> >
> >
> >
> > .... The problem seems to be on the "null" comparison... Is is a
> > correct thing to compare form handles to null ?
> >
> > Thank you very much, microsoftmen!