cad sunny

cad sunny

  • NA
  • 138
  • 22.9k

mdi parent and child

Mar 18 2020 10:31 AM
i have 3 forms.
 
form1 is main form i.e parent form and ismdicontainer propery set to true in form1.
  1. //here is form 1 button click for form 2 open  
  2. private void button1_Click(object sender, EventArgs e)  
  3. {  
  4. Form2 f2 = new Form2();  
  5. f2.ShowDialog();  
  6. }  
now i want to form 2 button click then form2 close and form3 open a child in to form1 parent.
trying below code
  1. // form2 button click for form3 open and form 2 close  
  2. private void button1_Click(object sender, EventArgs e)  
  3. {  
  4. //hide form2  
  5. this.Hide();  
  6. //open form 3  
  7. Form3 f3 = new Form3();  
  8. f3.MdiParent = Form1.ActiveForm;  
  9. f3.Show();  
  10. //close form2  
  11. this.Close();  
  12. }  
form 2 closed but form3 not open as a child form3 to parent form1.
 
please share correct code.its helpful for me.iam new in this.just iam learning and try to make small application.
sorry for my bad launguage.

Answers (7)