| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools | Rate Thread |
|
|
|
| |
|
Herfried K. Wagner [MVP]
Guest
Posts: n/a
|
"Mike" <(E-Mail Removed)> schrieb:
> I've found that if the user clicks the Close button > or clicks to use the Control box when closing a child > form, it doesn't initiate an event in the main form > even <http://groups.google.de/groups?selm=...TNGP11.phx.gbl > -- Herfried K. Wagner MVP · VB Classic, VB.NET <http://www.mvps.org/dotnet> |
|
||
|
||||
|
Mike
Guest
Posts: n/a
|
Thanks for the reply, Herfried.
As I mentioned in the original post, I've already tried using a delegate to notify the main form when the child is closed. Is there another way? -Mike "Herfried K. Wagner [MVP]" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... > "Mike" <(E-Mail Removed)> schrieb: > > I've found that if the user clicks the Close button > > or clicks to use the Control box when closing a child > > form, it doesn't initiate an event in the main form > > even > > <http://groups.google.de/groups?selm=...TNGP11.phx.gbl > > > > -- > Herfried K. Wagner > MVP · VB Classic, VB.NET > <http://www.mvps.org/dotnet> > > |
|
||
|
||||
|
Ying-Shen Yu[MS]
Guest
Posts: n/a
|
Hi Mike,
You won't get the Ctrl+F4 easily by just tieing it on a menu, because it's an system-defined hotkey. And I have some questions on your problem, From your description, I knew you have an event handler names FileClose_Click, is it implemented by yourself? and I didn't understand the words >However, "FileClose_Click" expects >the child to be closed by this time and, evidently, it's not (I use >"this.ActiveMdiChild" to detect this). If you can make you problem clearer , I think we can provide more solutions or work arounds, thanks! Kind regards, Ying-Shen Yu [MS] Microsoft Support Engineer This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. 2001 Microsoft Corporation. All rights reserved. -------------------- | From: "Mike" <(E-Mail Removed)> | Subject: Detecting When An MDI Child Is Closing | Date: Thu, 4 Sep 2003 18:00:22 -0400 | Lines: 19 | X-Priority: 3 | X-MSMail-Priority: Normal | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 | Message-ID: <##C#x$(E-Mail Removed)> | Newsgroups: microsoft.public.dotnet.framework.windowsforms | NNTP-Posting-Host: dialup-171.75.39.10.dial1.washington1.level3.net 171.75.39.10 | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.windowsforms:51667 | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms | | I've found that if the user clicks the Close button or clicks to use the | Control box when closing a child form, it doesn't initiate an event in the | main form even though I've tied Ctrl+F4 to a main form event, | "FileClose_Click", for some additional processing. So, using Ctrl+F4 or | File\Close from the main menu work fine, but I need to tie in the mouse | clicks. | | I've tried firing a user event when the "<form name>_Closed" and "<form | name>_Closing" events are fired to the listening main form so that | "FileClose_Click" can then be called. However, "FileClose_Click" expects | the child to be closed by this time and, evidently, it's not (I use | "this.ActiveMdiChild" to detect this). | | Is there a way to do this? Thanks. | | | -Mike | | | |
|
||
|
||||
|
Mike
Guest
Posts: n/a
|
Thanks for your reply, Ying-Shen.
Yes, I'm implementing FileClose_Click() myself in the parent form when the user selects File\Close from the main menu (see inline comments): private void FileClose_Click(object sender, System.EventArgs e) { Form activeForm = this.ActiveMdiChild; if( activeForm != null) activeForm.Close(); // With only one child open, I expect activeForm to now be null. activeForm = this.ActiveMdiChild; // But, the form at this point is NOT null and the following code // is NOT executed when the user uses the mouse to close the form. if( activeForm == null ) { mniView.Enabled = false; mniChannel.Enabled = false; } } FileClose_Click() works fine from the main menu (File\Close), and when Ctrl+F4 is pressed. However, when the user closes the child form with a mouse click (either the control box Close or the "X" button), I call the above method through a delegate. The inline comments describe what's happening in this case. How can I make this work? Thank you. -Mike "Ying-Shen Yu[MS]" <v-(E-Mail Removed)> wrote in message news:(E-Mail Removed)... > Hi Mike, > You won't get the Ctrl+F4 easily by just tieing it on a menu, because > it's an system-defined hotkey. > And I have some questions on your problem, From your description, I knew > you have an event handler > names FileClose_Click, is it implemented by yourself? and I didn't > understand the words > >However, "FileClose_Click" expects > >the child to be closed by this time and, evidently, it's not (I use > >"this.ActiveMdiChild" to detect this). > > If you can make you problem clearer , I think we can provide more solutions > or work arounds, thanks! > > > > > Kind regards, > > Ying-Shen Yu [MS] > Microsoft Support Engineer > > This posting is provided "AS IS" with no warranties, and confers no rights. > You assume all risk for your use. 2001 Microsoft Corporation. All rights > reserved. > -------------------- > | From: "Mike" <(E-Mail Removed)> > | Subject: Detecting When An MDI Child Is Closing > | Date: Thu, 4 Sep 2003 18:00:22 -0400 > | Lines: 19 > | X-Priority: 3 > | X-MSMail-Priority: Normal > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 > | Message-ID: <##C#x$(E-Mail Removed)> > | Newsgroups: microsoft.public.dotnet.framework.windowsforms > | NNTP-Posting-Host: dialup-171.75.39.10.dial1.washington1.level3.net > 171.75.39.10 > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl > | Xref: cpmsftngxa06.phx.gbl > microsoft.public.dotnet.framework.windowsforms:51667 > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms > | > | I've found that if the user clicks the Close button or clicks to use the > | Control box when closing a child form, it doesn't initiate an event in the > | main form even though I've tied Ctrl+F4 to a main form event, > | "FileClose_Click", for some additional processing. So, using Ctrl+F4 or > | File\Close from the main menu work fine, but I need to tie in the mouse > | clicks. > | > | I've tried firing a user event when the "<form name>_Closed" and "<form > | name>_Closing" events are fired to the listening main form so that > | "FileClose_Click" can then be called. However, "FileClose_Click" expects > | the child to be closed by this time and, evidently, it's not (I use > | "this.ActiveMdiChild" to detect this). > | > | Is there a way to do this? Thanks. > | > | > | -Mike > | > | > | > |
|
||
|
||||
|
Ying-Shen Yu[MS]
Guest
Posts: n/a
|
Hi mike,
let me repeat your problem, to my understanding you want to get informed when the last MdiChild window is closed?right? You may try this way. <code> //put the code in your mainform private void mnuNew_Click(object sender, System.EventArgs e) { ChildForm child = new ChildForm(); child.MdiParent = this; child.Closing += new CancelEventHandler(child_Closing); child.Closed += new EventHandler(child_Closed); child.Show(); } private void menuItem3_Click(object sender, System.EventArgs e) { Form activeForm = this.ActiveMdiChild; if( activeForm != null) activeForm.Close(); } private void child_Closing(object sender, CancelEventArgs e) { //put your confirmation dialog here. } private void child_Closed(object sender, EventArgs e) { //the current form is closed and being removed from the array, but for now //it's still there. if (this.MdiChildren.Length == 1) { MessageBox.Show("OnNoMdiChild()"); //OnNoMdiChild(); } } </code> If you still have problems on this issue, please let me know, thanks! Kind regards, Ying-Shen Yu [MS] Microsoft Support Engineer This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. 2001 Microsoft Corporation. All rights reserved. -------------------- | From: "Mike" <(E-Mail Removed)> | References: <##C#x$(E-Mail Removed)> <(E-Mail Removed)> | Subject: Re: Detecting When An MDI Child Is Closing | Date: Mon, 8 Sep 2003 12:05:24 -0400 | Lines: 112 | X-Priority: 3 | X-MSMail-Priority: Normal | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 | Message-ID: <(E-Mail Removed)> | Newsgroups: microsoft.public.dotnet.framework.windowsforms | NNTP-Posting-Host: dialup-171.75.39.63.dial1.washington1.level3.net 171.75.39.63 | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.windowsforms:51882 | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms | | Thanks for your reply, Ying-Shen. | | Yes, I'm implementing FileClose_Click() myself in the parent form | when the user selects File\Close from the main menu | (see inline comments): | | | private void FileClose_Click(object sender, System.EventArgs e) | { | Form activeForm = this.ActiveMdiChild; | | if( activeForm != null) | activeForm.Close(); | | // With only one child open, I expect activeForm to now be null. | activeForm = this.ActiveMdiChild; | | // But, the form at this point is NOT null and the following code | // is NOT executed when the user uses the mouse to close the form. | if( activeForm == null ) | { | mniView.Enabled = false; | mniChannel.Enabled = false; | } | } | | | FileClose_Click() works fine from the main menu (File\Close), and when | Ctrl+F4 is pressed. | | However, when the user closes the child form with a mouse click (either | the control box Close or the "X" button), I call the above method through | a delegate. The inline comments describe what's happening in | this case. | | How can I make this work? Thank you. | | | -Mike | | "Ying-Shen Yu[MS]" <v-(E-Mail Removed)> wrote in message | news:(E-Mail Removed)... | > Hi Mike, | > You won't get the Ctrl+F4 easily by just tieing it on a menu, because | > it's an system-defined hotkey. | > And I have some questions on your problem, From your description, I knew | > you have an event handler | > names FileClose_Click, is it implemented by yourself? and I didn't | > understand the words | > >However, "FileClose_Click" expects | > >the child to be closed by this time and, evidently, it's not (I use | > >"this.ActiveMdiChild" to detect this). | > | > If you can make you problem clearer , I think we can provide more | solutions | > or work arounds, thanks! | > | > | > | > | > Kind regards, | > | > Ying-Shen Yu [MS] | > Microsoft Support Engineer | > | > This posting is provided "AS IS" with no warranties, and confers no | rights. | > You assume all risk for your use. 2001 Microsoft Corporation. All rights | > reserved. | > -------------------- | > | From: "Mike" <(E-Mail Removed)> | > | Subject: Detecting When An MDI Child Is Closing | > | Date: Thu, 4 Sep 2003 18:00:22 -0400 | > | Lines: 19 | > | X-Priority: 3 | > | X-MSMail-Priority: Normal | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 | > | Message-ID: <##C#x$(E-Mail Removed)> | > | Newsgroups: microsoft.public.dotnet.framework.windowsforms | > | NNTP-Posting-Host: dialup-171.75.39.10.dial1.washington1.level3.net | > 171.75.39.10 | > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl | > | Xref: cpmsftngxa06.phx.gbl | > microsoft.public.dotnet.framework.windowsforms:51667 | > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms | > | | > | I've found that if the user clicks the Close button or clicks to use the | > | Control box when closing a child form, it doesn't initiate an event in | the | > | main form even though I've tied Ctrl+F4 to a main form event, | > | "FileClose_Click", for some additional processing. So, using Ctrl+F4 or | > | File\Close from the main menu work fine, but I need to tie in the mouse | > | clicks. | > | | > | I've tried firing a user event when the "<form name>_Closed" and "<form | > | name>_Closing" events are fired to the listening main form so that | > | "FileClose_Click" can then be called. However, "FileClose_Click" | expects | > | the child to be closed by this time and, evidently, it's not (I use | > | "this.ActiveMdiChild" to detect this). | > | | > | Is there a way to do this? Thanks. | > | | > | | > | -Mike | > | | > | | > | | > | | | |
|
||
|
||||
|
Mike
Guest
Posts: n/a
|
That worked!
Where should I detach the event handler, i.e. "child.Closed -= new EventHandler(child_Closed)" ? Thank you, Ying-Shen. -Mike "Ying-Shen Yu[MS]" <v-(E-Mail Removed)> wrote in message news:B%(E-Mail Removed)... > Hi mike, > let me repeat your problem, to my understanding you want to get > informed when the last MdiChild window is closed?right? You may try this > way. > <code> > //put the code in your mainform > private void mnuNew_Click(object sender, System.EventArgs e) > { > ChildForm child = new ChildForm(); > child.MdiParent = this; > child.Closing += new CancelEventHandler(child_Closing); > child.Closed += new EventHandler(child_Closed); > child.Show(); > } > > private void menuItem3_Click(object sender, System.EventArgs e) > { > Form activeForm = this.ActiveMdiChild; > if( activeForm != null) > activeForm.Close(); > } > > private void child_Closing(object sender, CancelEventArgs e) > { > //put your confirmation dialog here. > } > > private void child_Closed(object sender, EventArgs e) > { > //the current form is closed and being removed from the array, but for > now > //it's still there. > if (this.MdiChildren.Length == 1) > { > MessageBox.Show("OnNoMdiChild()"); > //OnNoMdiChild(); > } > } > </code> > If you still have problems on this issue, please let me know, > thanks! > > Kind regards, > > Ying-Shen Yu [MS] > Microsoft Support Engineer > > This posting is provided "AS IS" with no warranties, and confers no rights. > You assume all risk for your use. 2001 Microsoft Corporation. All rights > reserved. > -------------------- > | From: "Mike" <(E-Mail Removed)> > | References: <##C#x$(E-Mail Removed)> > <(E-Mail Removed)> > | Subject: Re: Detecting When An MDI Child Is Closing > | Date: Mon, 8 Sep 2003 12:05:24 -0400 > | Lines: 112 > | X-Priority: 3 > | X-MSMail-Priority: Normal > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 > | Message-ID: <(E-Mail Removed)> > | Newsgroups: microsoft.public.dotnet.framework.windowsforms > | NNTP-Posting-Host: dialup-171.75.39.63.dial1.washington1.level3.net > 171.75.39.63 > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl > | Xref: cpmsftngxa06.phx.gbl > microsoft.public.dotnet.framework.windowsforms:51882 > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms > | > | Thanks for your reply, Ying-Shen. > | > | Yes, I'm implementing FileClose_Click() myself in the parent form > | when the user selects File\Close from the main menu > | (see inline comments): > | > | > | private void FileClose_Click(object sender, System.EventArgs e) > | { > | Form activeForm = this.ActiveMdiChild; > | > | if( activeForm != null) > | activeForm.Close(); > | > | // With only one child open, I expect activeForm to now be null. > | activeForm = this.ActiveMdiChild; > | > | // But, the form at this point is NOT null and the following code > | // is NOT executed when the user uses the mouse to close the form. > | if( activeForm == null ) > | { > | mniView.Enabled = false; > | mniChannel.Enabled = false; > | } > | } > | > | > | FileClose_Click() works fine from the main menu (File\Close), and when > | Ctrl+F4 is pressed. > | > | However, when the user closes the child form with a mouse click (either > | the control box Close or the "X" button), I call the above method through > | a delegate. The inline comments describe what's happening in > | this case. > | > | How can I make this work? Thank you. > | > | > | -Mike > | > | "Ying-Shen Yu[MS]" <v-(E-Mail Removed)> wrote in message > | news:(E-Mail Removed)... > | > Hi Mike, > | > You won't get the Ctrl+F4 easily by just tieing it on a menu, > because > | > it's an system-defined hotkey. > | > And I have some questions on your problem, From your description, I knew > | > you have an event handler > | > names FileClose_Click, is it implemented by yourself? and I didn't > | > understand the words > | > >However, "FileClose_Click" expects > | > >the child to be closed by this time and, evidently, it's not (I use > | > >"this.ActiveMdiChild" to detect this). > | > > | > If you can make you problem clearer , I think we can provide more > | solutions > | > or work arounds, thanks! > | > > | > > | > > | > > | > Kind regards, > | > > | > Ying-Shen Yu [MS] > | > Microsoft Support Engineer > | > > | > This posting is provided "AS IS" with no warranties, and confers no > | rights. > | > You assume all risk for your use. 2001 Microsoft Corporation. All > rights > | > reserved. > | > -------------------- > | > | From: "Mike" <(E-Mail Removed)> > | > | Subject: Detecting When An MDI Child Is Closing > | > | Date: Thu, 4 Sep 2003 18:00:22 -0400 > | > | Lines: 19 > | > | X-Priority: 3 > | > | X-MSMail-Priority: Normal > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 > | > | Message-ID: <##C#x$(E-Mail Removed)> > | > | Newsgroups: microsoft.public.dotnet.framework.windowsforms > | > | NNTP-Posting-Host: dialup-171.75.39.10.dial1.washington1.level3.net > | > 171.75.39.10 > | > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl > | > | Xref: cpmsftngxa06.phx.gbl > | > microsoft.public.dotnet.framework.windowsforms:51667 > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms > | > | > | > | I've found that if the user clicks the Close button or clicks to use > the > | > | Control box when closing a child form, it doesn't initiate an event in > | the > | > | main form even though I've tied Ctrl+F4 to a main form event, > | > | "FileClose_Click", for some additional processing. So, using Ctrl+F4 > or > | > | File\Close from the main menu work fine, but I need to tie in the > mouse > | > | clicks. > | > | > | > | I've tried firing a user event when the "<form name>_Closed" and > "<form > | > | name>_Closing" events are fired to the listening main form so that > | > | "FileClose_Click" can then be called. However, "FileClose_Click" > | expects > | > | the child to be closed by this time and, evidently, it's not (I use > | > | "this.ActiveMdiChild" to detect this). > | > | > | > | Is there a way to do this? Thanks. > | > | > | > | > | > | -Mike > | > | > | > | > | > | > | > > | > | > | > |
|
||
|
||||
|
Ying-Shen Yu[MS]
Guest
Posts: n/a
|
Hi Mike,
I'm glad to hear that you solved the problem. And about your last question, I'm not clear about why you want to remove the handler manually, The Handler will be removed when the child form is GCed, although the form object will not be GCed immediately, but since it has been closed, the event will not be fired twice, right? I think you may safely leave this to Winform and CLR. If you do want to remove the handler explicitly, you may try removing it in OnClose event. If this is not helpful to your problem, please let me know. Thanks! Kind regards, Ying-Shen Yu [MS] Microsoft Support Engineer This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. 2001 Microsoft Corporation. All rights reserved. -------------------- | From: "Mike" <(E-Mail Removed)> | References: <##C#x$(E-Mail Removed)> <(E-Mail Removed)> <(E-Mail Removed)> <B#(E-Mail Removed)> | Subject: Re: Detecting When An MDI Child Is Closing | Date: Tue, 9 Sep 2003 15:30:34 -0400 | Lines: 211 | X-Priority: 3 | X-MSMail-Priority: Normal | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 | Message-ID: <(E-Mail Removed)> | Newsgroups: microsoft.public.dotnet.framework.windowsforms | NNTP-Posting-Host: dialup-171.75.39.29.dial1.washington1.level3.net 171.75.39.29 | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.windowsforms:51969 | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms | | That worked! | | Where should I detach the event handler, | i.e. "child.Closed -= new EventHandler(child_Closed)" ? | | Thank you, Ying-Shen. | | | -Mike | | "Ying-Shen Yu[MS]" <v-(E-Mail Removed)> wrote in message | news:B%(E-Mail Removed)... | > Hi mike, | > let me repeat your problem, to my understanding you want to get | > informed when the last MdiChild window is closed?right? You may try this | > way. | > <code> | > //put the code in your mainform | > private void mnuNew_Click(object sender, System.EventArgs e) | > { | > ChildForm child = new ChildForm(); | > child.MdiParent = this; | > child.Closing += new CancelEventHandler(child_Closing); | > child.Closed += new EventHandler(child_Closed); | > child.Show(); | > } | > | > private void menuItem3_Click(object sender, System.EventArgs e) | > { | > Form activeForm = this.ActiveMdiChild; | > if( activeForm != null) | > activeForm.Close(); | > } | > | > private void child_Closing(object sender, CancelEventArgs e) | > { | > //put your confirmation dialog here. | > } | > | > private void child_Closed(object sender, EventArgs e) | > { | > //the current form is closed and being removed from the array, but for | > now | > //it's still there. | > if (this.MdiChildren.Length == 1) | > { | > MessageBox.Show("OnNoMdiChild()"); | > //OnNoMdiChild(); | > } | > } | > </code> | > If you still have problems on this issue, please let me know, | > thanks! | > | > Kind regards, | > | > Ying-Shen Yu [MS] | > Microsoft Support Engineer | > | > This posting is provided "AS IS" with no warranties, and confers no | rights. | > You assume all risk for your use. 2001 Microsoft Corporation. All rights | > reserved. | > -------------------- | > | From: "Mike" <(E-Mail Removed)> | > | References: <##C#x$(E-Mail Removed)> | > <(E-Mail Removed)> | > | Subject: Re: Detecting When An MDI Child Is Closing | > | Date: Mon, 8 Sep 2003 12:05:24 -0400 | > | Lines: 112 | > | X-Priority: 3 | > | X-MSMail-Priority: Normal | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 | > | Message-ID: <(E-Mail Removed)> | > | Newsgroups: microsoft.public.dotnet.framework.windowsforms | > | NNTP-Posting-Host: dialup-171.75.39.63.dial1.washington1.level3.net | > 171.75.39.63 | > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl | > | Xref: cpmsftngxa06.phx.gbl | > microsoft.public.dotnet.framework.windowsforms:51882 | > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms | > | | > | Thanks for your reply, Ying-Shen. | > | | > | Yes, I'm implementing FileClose_Click() myself in the parent form | > | when the user selects File\Close from the main menu | > | (see inline comments): | > | | > | | > | private void FileClose_Click(object sender, System.EventArgs e) | > | { | > | Form activeForm = this.ActiveMdiChild; | > | | > | if( activeForm != null) | > | activeForm.Close(); | > | | > | // With only one child open, I expect activeForm to now be null. | > | activeForm = this.ActiveMdiChild; | > | | > | // But, the form at this point is NOT null and the following code | > | // is NOT executed when the user uses the mouse to close the form. | > | if( activeForm == null ) | > | { | > | mniView.Enabled = false; | > | mniChannel.Enabled = false; | > | } | > | } | > | | > | | > | FileClose_Click() works fine from the main menu (File\Close), and when | > | Ctrl+F4 is pressed. | > | | > | However, when the user closes the child form with a mouse click (either | > | the control box Close or the "X" button), I call the above method | through | > | a delegate. The inline comments describe what's happening in | > | this case. | > | | > | How can I make this work? Thank you. | > | | > | | > | -Mike | > | | > | "Ying-Shen Yu[MS]" <v-(E-Mail Removed)> wrote in message | > | news:(E-Mail Removed)... | > | > Hi Mike, | > | > You won't get the Ctrl+F4 easily by just tieing it on a menu, | > because | > | > it's an system-defined hotkey. | > | > And I have some questions on your problem, From your description, I | knew | > | > you have an event handler | > | > names FileClose_Click, is it implemented by yourself? and I didn't | > | > understand the words | > | > >However, "FileClose_Click" expects | > | > >the child to be closed by this time and, evidently, it's not (I use | > | > >"this.ActiveMdiChild" to detect this). | > | > | > | > If you can make you problem clearer , I think we can provide more | > | solutions | > | > or work arounds, thanks! | > | > | > | > | > | > | > | > | > | > Kind regards, | > | > | > | > Ying-Shen Yu [MS] | > | > Microsoft Support Engineer | > | > | > | > This posting is provided "AS IS" with no warranties, and confers no | > | rights. | > | > You assume all risk for your use. 2001 Microsoft Corporation. All | > rights | > | > reserved. | > | > -------------------- | > | > | From: "Mike" <(E-Mail Removed)> | > | > | Subject: Detecting When An MDI Child Is Closing | > | > | Date: Thu, 4 Sep 2003 18:00:22 -0400 | > | > | Lines: 19 | > | > | X-Priority: 3 | > | > | X-MSMail-Priority: Normal | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 | > | > | Message-ID: <##C#x$(E-Mail Removed)> | > | > | Newsgroups: microsoft.public.dotnet.framework.windowsforms | > | > | NNTP-Posting-Host: dialup-171.75.39.10.dial1.washington1.level3.net | > | > 171.75.39.10 | > | > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl | > | > | Xref: cpmsftngxa06.phx.gbl | > | > microsoft.public.dotnet.framework.windowsforms:51667 | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms | > | > | | > | > | I've found that if the user clicks the Close button or clicks to use | > the | > | > | Control box when closing a child form, it doesn't initiate an event | in | > | the | > | > | main form even though I've tied Ctrl+F4 to a main form event, | > | > | "FileClose_Click", for some additional processing. So, using | Ctrl+F4 | > or | > | > | File\Close from the main menu work fine, but I need to tie in the | > mouse | > | > | clicks. | > | > | | > | > | I've tried firing a user event when the "<form name>_Closed" and | > "<form | > | > | name>_Closing" events are fired to the listening main form so that | > | > | "FileClose_Click" can then be called. However, "FileClose_Click" | > | expects | > | > | the child to be closed by this time and, evidently, it's not (I use | > | > | "this.ActiveMdiChild" to detect this). | > | > | | > | > | Is there a way to do this? Thanks. | > | > | | > | > | | > | > | -Mike | > | > | | > | > | | > | > | | > | > | > | | > | | > | | > | | | | | |
|
||
|
||||
|
Mike
Guest
Posts: n/a
|
Ying-Shen,
I had thought that it was always good practice to detach any event handlers before exiting. If that's not necessary, then I won't worry about it. Thank you for your help. -Mike "Ying-Shen Yu[MS]" <v-(E-Mail Removed)> wrote in message news:(E-Mail Removed)... > Hi Mike, > I'm glad to hear that you solved the problem. And about your last > question, > I'm not clear about why you want to remove the handler manually, The > Handler will be removed when > the child form is GCed, although the form object will not be GCed > immediately, but since it has been closed, > the event will not be fired twice, right? I think you may safely leave this > to Winform and CLR. > If you do want to remove the handler explicitly, you may try removing it in > OnClose event. > > If this is not helpful to your problem, please let me know. > > Thanks! > > > Kind regards, > > Ying-Shen Yu [MS] > Microsoft Support Engineer > > This posting is provided "AS IS" with no warranties, and confers no rights. > You assume all risk for your use. 2001 Microsoft Corporation. All rights > reserved. > -------------------- > | From: "Mike" <(E-Mail Removed)> > | References: <##C#x$(E-Mail Removed)> > <(E-Mail Removed)> > <(E-Mail Removed)> > <B#(E-Mail Removed)> > | Subject: Re: Detecting When An MDI Child Is Closing > | Date: Tue, 9 Sep 2003 15:30:34 -0400 > | Lines: 211 > | X-Priority: 3 > | X-MSMail-Priority: Normal > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 > | Message-ID: <(E-Mail Removed)> > | Newsgroups: microsoft.public.dotnet.framework.windowsforms > | NNTP-Posting-Host: dialup-171.75.39.29.dial1.washington1.level3.net > 171.75.39.29 > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl > | Xref: cpmsftngxa06.phx.gbl > microsoft.public.dotnet.framework.windowsforms:51969 > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms > | > | That worked! > | > | Where should I detach the event handler, > | i.e. "child.Closed -= new EventHandler(child_Closed)" ? > | > | Thank you, Ying-Shen. > | > | > | -Mike > | > | "Ying-Shen Yu[MS]" <v-(E-Mail Removed)> wrote in message > | news:B%(E-Mail Removed)... > | > Hi mike, > | > let me repeat your problem, to my understanding you want to get > | > informed when the last MdiChild window is closed?right? You may try this > | > way. > | > <code> > | > //put the code in your mainform > | > private void mnuNew_Click(object sender, System.EventArgs e) > | > { > | > ChildForm child = new ChildForm(); > | > child.MdiParent = this; > | > child.Closing += new CancelEventHandler(child_Closing); > | > child.Closed += new EventHandler(child_Closed); > | > child.Show(); > | > } > | > > | > private void menuItem3_Click(object sender, System.EventArgs e) > | > { > | > Form activeForm = this.ActiveMdiChild; > | > if( activeForm != null) > | > activeForm.Close(); > | > } > | > > | > private void child_Closing(object sender, CancelEventArgs e) > | > { > | > //put your confirmation dialog here. > | > } > | > > | > private void child_Closed(object sender, EventArgs e) > | > { > | > //the current form is closed and being removed from the array, but for > | > now > | > //it's still there. > | > if (this.MdiChildren.Length == 1) > | > { > | > MessageBox.Show("OnNoMdiChild()"); > | > //OnNoMdiChild(); > | > } > | > } > | > </code> > | > If you still have problems on this issue, please let me know, > | > thanks! > | > > | > Kind regards, > | > > | > Ying-Shen Yu [MS] > | > Microsoft Support Engineer > | > > | > This posting is provided "AS IS" with no warranties, and confers no > | rights. > | > You assume all risk for your use. 2001 Microsoft Corporation. All > rights > | > reserved. > | > -------------------- > | > | From: "Mike" <(E-Mail Removed)> > | > | References: <##C#x$(E-Mail Removed)> > | > <(E-Mail Removed)> > | > | Subject: Re: Detecting When An MDI Child Is Closing > | > | Date: Mon, 8 Sep 2003 12:05:24 -0400 > | > | Lines: 112 > | > | X-Priority: 3 > | > | X-MSMail-Priority: Normal > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 > | > | Message-ID: <(E-Mail Removed)> > | > | Newsgroups: microsoft.public.dotnet.framework.windowsforms > | > | NNTP-Posting-Host: dialup-171.75.39.63.dial1.washington1.level3.net > | > 171.75.39.63 > | > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl > | > | Xref: cpmsftngxa06.phx.gbl > | > microsoft.public.dotnet.framework.windowsforms:51882 > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms > | > | > | > | Thanks for your reply, Ying-Shen. > | > | > | > | Yes, I'm implementing FileClose_Click() myself in the parent form > | > | when the user selects File\Close from the main menu > | > | (see inline comments): > | > | > | > | > | > | private void FileClose_Click(object sender, System.EventArgs e) > | > | { > | > | Form activeForm = this.ActiveMdiChild; > | > | > | > | if( activeForm != null) > | > | activeForm.Close(); > | > | > | > | // With only one child open, I expect activeForm to now be null. > | > | activeForm = this.ActiveMdiChild; > | > | > | > | // But, the form at this point is NOT null and the following code > | > | // is NOT executed when the user uses the mouse to close the form. > | > | if( activeForm == null ) > | > | { > | > | mniView.Enabled = false; > | > | mniChannel.Enabled = false; > | > | } > | > | } > | > | > | > | > | > | FileClose_Click() works fine from the main menu (File\Close), and when > | > | Ctrl+F4 is pressed. > | > | > | > | However, when the user closes the child form with a mouse click > (either > | > | the control box Close or the "X" button), I call the above method > | through > | > | a delegate. The inline comments describe what's happening in > | > | this case. > | > | > | > | How can I make this work? Thank you. > | > | > | > | > | > | -Mike > | > | > | > | "Ying-Shen Yu[MS]" <v-(E-Mail Removed)> wrote in message > | > | news:(E-Mail Removed)... > | > | > Hi Mike, > | > | > You won't get the Ctrl+F4 easily by just tieing it on a menu, > | > because > | > | > it's an system-defined hotkey. > | > | > And I have some questions on your problem, From your description, I > | knew > | > | > you have an event handler > | > | > names FileClose_Click, is it implemented by yourself? and I didn't > | > | > understand the words > | > | > >However, "FileClose_Click" expects > | > | > >the child to be closed by this time and, evidently, it's not (I use > | > | > >"this.ActiveMdiChild" to detect this). > | > | > > | > | > If you can make you problem clearer , I think we can provide more > | > | solutions > | > | > or work arounds, thanks! > | > | > > | > | > > | > | > > | > | > > | > | > Kind regards, > | > | > > | > | > Ying-Shen Yu [MS] > | > | > Microsoft Support Engineer > | > | > > | > | > This posting is provided "AS IS" with no warranties, and confers no > | > | rights. > | > | > You assume all risk for your use. 2001 Microsoft Corporation. All > | > rights > | > | > reserved. > | > | > -------------------- > | > | > | From: "Mike" <(E-Mail Removed)> > | > | > | Subject: Detecting When An MDI Child Is Closing > | > | > | Date: Thu, 4 Sep 2003 18:00:22 -0400 > | > | > | Lines: 19 > | > | > | X-Priority: 3 > | > | > | X-MSMail-Priority: Normal > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 > | > | > | Message-ID: <##C#x$(E-Mail Removed)> > | > | > | Newsgroups: microsoft.public.dotnet.framework.windowsforms > | > | > | NNTP-Posting-Host: > dialup-171.75.39.10.dial1.washington1.level3.net > | > | > 171.75.39.10 > | > | > | Path: > cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl > | > | > | Xref: cpmsftngxa06.phx.gbl > | > | > microsoft.public.dotnet.framework.windowsforms:51667 > | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms > | > | > | > | > | > | I've found that if the user clicks the Close button or clicks to > use > | > the > | > | > | Control box when closing a child form, it doesn't initiate an > event > | in > | > | the > | > | > | main form even though I've tied Ctrl+F4 to a main form event, > | > | > | "FileClose_Click", for some additional processing. So, using > | Ctrl+F4 > | > or > | > | > | File\Close from the main menu work fine, but I need to tie in the > | > mouse > | > | > | clicks. > | > | > | > | > | > | I've tried firing a user event when the "<form name>_Closed" and > | > "<form > | > | > | name>_Closing" events are fired to the listening main form so that > | > | > | "FileClose_Click" can then be called. However, "FileClose_Click" > | > | expects > | > | > | the child to be closed by this time and, evidently, it's not (I > use > | > | > | "this.ActiveMdiChild" to detect this). > | > | > | > | > | > | Is there a way to do this? Thanks. > | > | > | > | > | > | > | > | > | -Mike > | > | > | > | > | > | > | > | > | > | > | > > | > | > | > | > | > | > | > > | > | > | > | > | > |
|
||
|
||||
|
|
|
| |
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assistance with detecting and closing app | =?Utf-8?B?Q2hyaXM=?= | Microsoft Dot NET | 1 | 1st Oct 2007 09:10 AM |
| Closing event in a MID Child form I don't know if the child form is closing or the main form is closing | **Developer** | Microsoft C# .NET | 1 | 19th Oct 2005 04:51 PM |
| Filesystemwatcher detecting File Closing. How ? | Sagaert Johan | Microsoft C# .NET | 3 | 6th Mar 2005 10:04 PM |
| detecting the session closing | Russell | Microsoft ASP .NET | 5 | 26th Jan 2005 07:00 PM |
| Detecting MDI child form closed? | T | Microsoft Dot NET Framework Forms | 1 | 5th Aug 2003 12:58 AM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |




