To restrict your Container Control to parent only certain types of controls, override as follows in your designer:
public class CustomContainerControlDesigner : ParentControlDesigner
{
public override bool CanParent( Control control )
{
return control is TextBox; // only allow TextBox children
}
}
To restrict your Control to get parented to by a certain type, do so in your Control's designer:
class CustomControlDesigner : ControlDesigner
{
public override bool CanBeParentedTo( IDesigner parentDesigner )
{
// CustomControl can be only parented to CustomParent
return parentDesigner is CustomParentDesigner;
// alternatively:
return parentDesigner.Component is CustomParent;
}
}
Contributed from George Shepherd's Windows Forms FAQ