Accessing public MDI parent members

JDT_71

Member
Joined
Jul 11, 2006
Messages
7
Programming Experience
Beginner
I have an MDI form with a Public Integer Variable. It also contains an MDI child form.

Can the MDI child form access the individual instance of that Public Integer Variable associated with that specific MDI Parent Form?

I have so far been solving the problem by having an variable of the parent form inside of the child form and setting it equal to that specific instance of the parent form from inside of the parent form before activating the child form. Then, I can change the properties of the parent form from inside of the child form. However, sometimes if I'm not careful, it can result in recursive instantiation (I'm not sure exactly what to call it) that results in an endless loop of memory consumption and eventually crashes the program. I hope I'm making sense. I'm not real profficient with MDI forms, so I'm probably going about it the wrong way. Any help would be appreciated.
 
Every MDI child already has a reference to its parent. You should know because you set it yourself. It's the MdiParent property. The thing is, that property is type Form, so you can only access members of the Form class directly. If you want to access members of your specific form type then you need to cast the MdiParent as that type, e.g.
VB.NET:
Dim myParent As Form1 = DirectCast(Me.MdiParent, Form1)
You can then access public members of the Form1 class through the myParent variable. For more information on using forms I suggest that you read the tutorial in my signature.
 
I meant to say the "first link in my signature", i.e. Multiple Forms. It doesn't deal with MDI specifically but it does deal with communicating between multiple forms, which this basically is once you know how to get the reference to the parent. Also note that the parent has MdiChildren and ActiveMdiChild properties.
 
Back
Top