开发者

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜