Re: Visible = False on Form_Closing... by DraguVaso
DraguVaso
Thu Jan 08 02:30:08 CST 2004
Unfortunately this doesn't work... I tryed it myself alreaddy before.
This code does the following: It first hides one MDIChild, and when you
click a second time on the "x" of the Parent, then it closes the whole
application.
The reason for that is simple: When you close your application, the
MIDChild_Closing-event is fired before the Parent_Closing-event: so you
aren't able to change the boolean-value before closing the MDIChilds. The
second time you click the boolean value is alreaddy changed (from the first
time), and than the application is properly shutted down.
The order of events is this:
Child_Closing
Parent_Closing
Child_Closed
Parent_Closed
So what I could do is: change the boolean in the Parent_Closing, and
evaluate it in the Child_Closed. Unfortunately: I can't find a way to cancel
the closing in the Closed-event...
Anybody any idea? I'm really stuck with this problem :-(
Pieter
"Norman Yuan" <normanyuan@RemoveThis.shaw.ca> wrote in message
news:7jXKb.15406$JQ1.5606@pd7tw1no...
> You can set closeing flag in the main form (MDI parent).
>
> in the Main form (MDI parent) class:
>
> public class frmMain:Form
> {
> private bool mClosing=false;
> public frmMain()
> {
> }
>
> internal bool MainFormClosing
> {
> get { return mClosing; }
> }
> .....
> ......
> private void frmMain_Closing(...)
> {
> mClosing=true;
> }
> }
>
> in the MDI child form class
>
> public frmChild:Form
> {
> ....
> ....
> private frmChild_Closing(....)
> {
> file://If the closing is caused by MDI parent, no CANCELLING
> frmMain f=(frmMain)this.Parent;
> if (f.MainFormClosing) return;
>
> file://Cancel closing
> e.Cancel=true
> this.Visible=false;
> }
> }
>
> The code is in C#, and very little differentce from VB.NET code and you
> should be able to read it.
>
> HTH
>
> "DraguVaso" <pietercoucke@hotmail.com> wrote in message
> news:3ffc316f$0$6081$ba620e4c@news.skynet.be...
> > Hi,
> >
> > I have a MDIForm with some MDIChilds. When the user clicks on the "x" in
> the
> > upper right corner, I don't want the MDIChild to be closed, but the
> property
> > Visible = False.
> >
> > So far no problem: I do this useing the Form_Closing-event in which I
> typed:
> > e.Cancel = True
> > Me.Visibible = False
> >
> > But: When I Close the MDIParent, it wont shut down the whole application
> > because of the fact that those MDIChilds cancel the closing!
> >
> > I tryed to put work with a boolean which is set to true when MDIParent
is
> > closed, and first evaluated in the MIDChild_Closing-event, but that
> doesn't
> > work either, because of the fact that the Closing-event of the MDIChilds
> are
> > fired before the Closing Event of the Parent...
> >
> > Anybody got any idea how to do this? Maybe with the Closed-event? This
> event
> > comes after the Closing-event, but I can't find someting in ot to Cancel
> the
> > closing of the form.
> >
> > I guess there must be a 'nicer' way to do this: Maybe by handling the
> click
> > on the "x", and when it is clicked not to close etc etc...
> >
> > Hoping for your help and thanks a lot in advance,
> >
> > Pieter
> >
> >
>
>