In .NET 1.1 a trick should be added to the composite control
to be able to view the composite control child-controls at design time
correctly.
The trick is by adding this new property:
Listing 22
public new void EnsureChildControls()
{
base.EnsureChildControls();
}
Since the Control class has the EnsureChildControls
implemented as protected, we need to add this method and, as you have noticed,
it is added with the keyword “new” which means we are not overriding the
EnsureChildControl of the parent class but rather giving a new implementation
of that which is nothing but calling the base EnsureChildControls method.
Then after that we add a Designer class as follows:
Listing 23
public class bhMoverDesigner: ControlDesigner
{
public override String GetDesignTimeHtml()
{
// Ensure the control is built
bhMover mover = this.Component as bhMover;
mover.EnsureChildControls();
return base.GetDesignTimeHtml();
}
}
In this designer class we have overridden the
GetDesignTimeHtml method which is used to show the control in design time in
the Visual Studio IDE. We simple get the instance of the control and then call its
EnsureChildControls method that we have just added above. This trick will take
care of showing the composite control together with its child controls at
design time.