tags:

views:

19

answers:

5

i have:

object[] obj = new object[button1, label1]; //
object parent; // some Panel

i need

for (int i = 0; i < obj.Length; i++) 
   obj[i].Parent = parent;

How to get it?

+1  A: 
var controls = new Control[] { button1, label1 };
Control parent = ...;

foreach (Control control in controls)
{
    control.Parent = parent;
}
Paul Ruane
A: 

Normal .NET parent/child relationships are created like this:

parent.Controls.Add(child);
John Fisher
A: 
object[] obj = new object[] { button1, label1 }; // create array of objects
object parent; // some Panel


for (int i = 0; i < obj.Length; i++)
{ 
   ((Control)obj[i]).Parent = parent;
}
gmcalab
A: 

u just using Controls? if this define ur array as bellow:

Control[] controls = new Control{button1, lable};
for (int i = 0; i < controls.Length; i++) 
   controls[i].Parent = parent;
SaeedAlg
A: 

Thanks a lot, guys )

4iNo
I see you're new but this is for answers, not comments. Please mark the answer you chose and comment in the appropriate comment section.
gmcalab