solus Posted April 15, 2003 Posted April 15, 2003 (edited) override close event How can I override the close event on a child window so that i can cancel it being closed without effecting the parent window? Here's the code i'm using to cancel the close event in my child window: private void StatusForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { e.Cancel = true; } Here is the code I use to open the child window initially: StatusForm chStatusForm = new StatusForm(); chStatusForm.MdiParent = this; chStatusForm.Show(); Edited April 15, 2003 by solus Quote Can't afford to be neutral on a moving train...
*Experts* Nerseus Posted April 15, 2003 *Experts* Posted April 15, 2003 What's wrong with the code you have? It looks perfect... -Ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Guest mutant Posted April 15, 2003 Posted April 15, 2003 I dont get how to do that too... Why would they make such a simple thing work like that? Quote
*Experts* Bucky Posted April 15, 2003 *Experts* Posted April 15, 2003 solus, you are currently not overriding the base class method you mentioned, you just made a subroutine. You need to either: a.) Change the sub name to OnClosing and add the override keyword, and change the parameters, like this: private override void OnClosing(System.ComponentModel.CancelEventArgs e) { e.Cancel = true; } or... b.) Make sure that the current sub is a delegate of the Closing event. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
solus Posted April 16, 2003 Author Posted April 16, 2003 I want it so the child window won't close unless the parent window is closed. Both bits of code effects both the child and parent so neither can be closed. Quote Can't afford to be neutral on a moving train...
*Experts* Bucky Posted April 16, 2003 *Experts* Posted April 16, 2003 In that case, create a boolean variable that can be accessed from both forms. When the parent form closes, set the boolean value to true. In the child form, check the value of the boolean variable, and if it's true then unload the form. You'll also probably want to set the variable back to false after closing the form. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
solus Posted April 17, 2003 Author Posted April 17, 2003 Oh yeah, good idea =] Quote Can't afford to be neutral on a moving train...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.