Saturday, 24 August 2013

Owned form and mdi parent

Owned form and mdi parent

this is my scenario and hope you can solve it for me
I have a MDI container form called "MainForm". In MainForm there is a
simple form call "Form1". In Form1 there is a button. every time you
pushed it, It open a new form which instance of "Form2". The followng code
is click button event.
Button_Click(){
Form2 frm=new Form2();
frm.mdiparnt=this.MdiParent;
this.addOwnedForm(frm);
frm.Visible=true;
}
and the following code tries to close owned forms when the user close Form1
Form1_CloseEvent(){
foreach(var item in this.ownedForm){
item.close();
}
}
But when the debugger steps into close event, just close Form1, and the
form2 instances remain open. what should I do to solve it

No comments:

Post a Comment