views:

433

answers:

2

I have a WinForms user control Host with a custom UI Editor. Through that editor, a child control (Child) can be added to Host.

(The UI Editor creates Child and sets Child.Parent = Host)

Child is handled through a Holder<Child> helper class, which is set as Tag property of e.g. a ListViewItem.

The respective code - some of it, at least - gets added to the form: Holder is created, and set as Tag, which is enough to be created at runtime, too.

However, Child is not visible to the designer - it is displayed, but it can't be selected, nor does it occur in the drop down list with controls for the parent form.

I would like to:

  • see the Child control in the designer, so that I can modify properties
  • get notified if the control is removed

Is this possible?


[edit] Thanks all for your input. I've decided to skip the designer - I hoped to throw together something quickly, but apparently it requires more planning than I should allow myself to spend on it right now.

+1  A: 

I can't say I fully understand exactly what you are trying to do.

If you are dealing with the problem of how a "child" Control of a UserControl placed on a Form at Design-Time can be made to function as a container onto which you can drag-and-drop other controls from the Toolbox : this CodeProject article by Henry Minute may be helpful : Designing Nested Controls. For example : you have a UserControl with a Panel inside it : an instance of the UserControl is placed on a Form : in the Design-time view of the Form : you want to be able to drag-drop controls onto the Panel in the UserControl and have them become child controls of the Panel : Henry's article will show you how to do that.

This from Microsoft : How to make a UserControl object acts as a control container design-time by using Visual C#

Perhaps might also be useful, although it seems like you already have this step accomplished.

BillW
@Designing nested Controls - added to my "Designer cheat sheet"
peterchen
+2  A: 

Usethis.Controls.Add(/*Instance of the child*/); on the host class. Then for the notification add event handler for the host's ControlRemoved event (this.ControlRemoved += new ControlEventHandler(Host_ControlRemoved);).

Jojo Sardez