Answered by:
Forms Dispose from parent, will it dispose child?

Question
-
Hello,
I do not understand how this works. I may be unsure of what the true definitions of parent and child forms are. I think a parent child relationships is made like thisclass Form: Form1 { private Form2 some_form; private void button1_Click(object sender, EventArgs e) { some_form = new Form2(); some_form.Show(); this.hide(); } }
If I am correct, when I dispose of a Form1 object, I do not see Form2 being disposed. Is there some way that I am supposed to create this relationship?
Answers
-
It means I was wrong. I did no tthink clearly but now I do understand that it sould be the case. I sort of suspected I was wrong when I posted that.
From your entire discourse I faile dto see you ultimate goal. What do you want to create? Do you want the child form to be killed when you dispose of the main form? You can either close the child form programmatically from the parent form or you can kill the process for the child while the parent is still alive. System.Diagnostics.Process. Find the window handle you need and kill it.
AlexB -
Types that own disposable fields should be disposable and dispose all disposible fields in its IDisposable implementation. If you are compiling your code under Visual Studio Team Suit your code will be flagged with warning CA1001
MSMVP VC++
All replies
-
-
I have the compact framework and this is not what I am seeing. I have 3 forms, each makes a child form with the syntax above. They are form1, form2, and form3. If I dispose of Form2, form3 is still visible...
I don't understand why...
Is this unique to the compact framework??
-
-
It means I was wrong. I did no tthink clearly but now I do understand that it sould be the case. I sort of suspected I was wrong when I posted that.
From your entire discourse I faile dto see you ultimate goal. What do you want to create? Do you want the child form to be killed when you dispose of the main form? You can either close the child form programmatically from the parent form or you can kill the process for the child while the parent is still alive. System.Diagnostics.Process. Find the window handle you need and kill it.
AlexB -
Types that own disposable fields should be disposable and dispose all disposible fields in its IDisposable implementation. If you are compiling your code under Visual Studio Team Suit your code will be flagged with warning CA1001
MSMVP VC++ -
The relationship needs to be handled via Form.AddOwnedForm Method.
MSDN Topic: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform.aspx
Child forms will be closed properly with parent.
Handle dispose functionality in OnClosed/OnClosing methods.
- Edited by Erez Robinson Wednesday, February 20, 2013 8:51 PM