To restrict your Container Control to parent only certain types of controls, override as follows in your designer:
public class MyContainerControlDesigner : ParentControlDesigner
{
public override /*ParentControlDesigner*/ bool CanParent(Control control)
{
// My Children can only be of type TextBox.
return (control is TextBox);
}
}
To restrict your Control to get parented to by a certain type, do so in your Control’s designer:
class MyControlDesigner : ControlDesigner
{
public override /*ControlDesigner*/ bool CanBeParentedTo(IDesigner parentDesigner)
{
// MyControl can be parent only by MyParent
return (parentDesigner is MyParentDesigner);
// or do this:
// return (parentDesigner.Component is MyParent);
}
}
Share with