Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys, I just want to ask how to instantiate or call my MDI parent on my Form1. My codes look like this.

Form2 frm2 = new Form2();
frm2.MdiParent = this; --------> this is the one that I want to instantiate on my Form2
frm2.Show();

My problem is I want to instantiate the this part on my syntax on MDIParent on the other form. Thank you guys. Looking forward for the reply.
Posted
Comments
Marvin Ma 6-Sep-13 4:07am    
Could you post the code for Form2 please?
Member 10095043 6-Sep-13 4:13am    
Yes it is. My problem is I want to reattach my child form to its MDI parent which is the Form1.
Codes Form1:

Codes for detach:
frm2.MdiParent = null; --> This codes is for the detachment of my child form in my MDIPARENT

Codes for reattch: Form2 Codes
//Instantiating Form1
Form1 frm1 = new Form1();
this.MdiParent = frm1; ----> this is the problem whenever I reattach the child form nothing happens.
Member 10095043 6-Sep-13 4:22am    
Do you think I can get the value of this on my form1 mdi parent?

1 solution

Codes for reattch: Form2 Codes
C#
//Instantiating Form1
Form1 frm1 = new Form1();
this.MdiParent = frm1;

this is the problem whenever I reattach the child form nothing happens.

No, it won't.
Because the instance of Form1 that you are "reattaching" to is not the original, and is not even displayed - it is a totally different instance! The keyword new here should give you a clue about this. :laugh:

It's like a car: if you put your mobile phone in the glove box of your car, and sell it to buy a new car, would you expect to find your phone in the new cars glove box?

When you "detach" the form2, either save the Parent instance and use that instance for reattaching, or better still create a events within Form2 which ask the Parent to detach and reattach the form. That way, form2 does not need to know about it's parent.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900