To compare unit types (for pixels only), use the Unit.Value property which returns a double giving the value in pixels. With this in mind and desiring a lower limit of 128 px wide, you might change the Width property to:
Public Property Width As Unit
Get
Return Me.Width
End Get
Set (ByVal Value As Unit)
If Value.Value<128.0 Then Value=Unit.Pixels(128)
MyBase.Width=Value
End Set
End Property
As far as the inner controls not showing up initially in the designer, I've seen this happen before when I have not forced the control to recreate its children and rerender after any change has been made. The following techniques have helped prevent this:
1. Override the Controls property of your custom control to force an EnsureChildControls each time the Control property is referenced:
Public Overrides ReadOnly Property Controls() As ControlCollection
Get
EnsureChildControls()
Return MyBase.Controls
End Get
End Property
2. In the setter of any property that would change the number of, types of, order of, etc. child controls, set the value of ChildControlsCreated to FALSE.
3. In your custom designer's GetDesignTimeHTML method, reference the custom controls child collection. Since you have included EnsureChildControls in the overriden Controls property, this should force a recreation of child controls and a re-rendering. Here's an example from one of my control's designers:
Public Class FieldDesigner
Inherits System.Web.UI.Design.ControlDesigner
Public Overrides Function GetDesignTimeHtml() As String
Dim DesignTimeHtml As String
Dim ControlToDesign As BaseField = CType(Component, BaseField)
Dim Controls As ControlCollection = ControlToDesign.Controls 'Reference Controls to force rerendering
DesignTimeHtml = MyBase.GetDesignTimeHtml()
If DesignTimeHtml.Length = 0 Then DesignTimeHtml = GetEmptyDesignTimeHtml()
Return DesignTimeHtml
End Function
End Class
Bill, WESNet Designs