parent vs controls.add

onepieceking

Well-known member
Joined
Sep 20, 2006
Messages
64
Programming Experience
1-3
Supposed i have created a picturebox (pbox) dynamically and i want to put the picturebox into panel1.

What is the difference between

VB.NET:
pbox.parent = panel1

and

VB.NET:
panel1.controls.add(pbox)

Both seem to work.
 
They both operates the same when setting the parent, but both have additional functionality the other can't provide.

If you somewhere get reference to a control (for example from an event) and need to get to its parent then this property is the only path (except iterating all controlcollections where it possibly might beling).

From the parents controlcollection you might want to to additional work related to this control and the others, which the single parent property can't give you.

(Note: I splitted your original post and made this new thread, please post unrelated requests as own threads.)
 
Back
Top