Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All...
I need some help in mdi parents .
will i have a parent and 5 mdi childs.
i know how to access the parent from mdichild.
but can i access the controls in child from parent and how ??
thx All.
Posted
Updated 15-May-10 4:57am
v2

Yeah - make them public instead of protected/private.
 
Share this answer
 
The Parent's MdiChildren property gives you an array of Forms. You need to cast the base Form that you want from the collection to the derived class that is your child. Once you have that, you can access public properties or methods you create in the child.

Don't make the control's themselves public!
 
Share this answer
 
As John said you need to make the access to the controls public. I carefully said access rather than making the controls public themselves because you are exposing the inner workings of the form, which is one of the tenets of object orientation; namely you should use encapsulation.

For instance, suppose you want to control the access to the checked property on a checkbox, you would wrap it up in a property and you'd call that instead. So you'd have a property that looks like this:
public bool HasTakenWarranty
{
  get { return chkWarranty.Checked; }
  set { chkWarranty.Checked = value; }
}
As you can see from this, you have wrapped up the access to the checked state so that you don't have to provide public access to all the properties on the control. This also means that you can provide one property/method that acts on more than control at a time.
 
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