set object method Parent
i have:
object[] obj = new obj开发者_如何学运维ect[button1, label1]; //
object parent; // some Panel
i need
for (int i = 0; i < obj.Length; i++)
obj[i].Parent = parent;
How to get it?
var controls = new Control[] { button1, label1 };
Control parent = ...;
foreach (Control control in controls)
{
control.Parent = parent;
}
Normal .NET parent/child relationships are created like this:
parent.Controls.Add(child);
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;
}
精彩评论