views:

201

answers:

1

more specifically, are these statements

ownerControl.GroupBox1.Controls.Remove(childControl);
ownerControl.Controls.Add(childControl);

an equivalent to

childControl.Parent = ownerControl;
+6  A: 

Looking in reflector, it looks like Parent just calls Add (when the new parent is non-null). The Controls.Add deals with taking it away from the old parent. So actually, the following are functionally equivalent (when ownerControl is not null):

ownerControl.Controls.Add(childControl); // note no Remove etc

and:

childControl.Parent = ownerControl;

Counter-intuitive, but a quick test shows that it works.

Marc Gravell