Live Chat Icon For mobile
Live Chat Icon

How do I restrict my Container Control to parent only certain types of Controls, and vice-versa, during design-time?

Platform: WinForms| Category: Custom Designers

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

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.