UserControl that acts like a container at design time.

IfYouSaySo

Well-known member
Joined
Jan 4, 2006
Messages
102
Location
Hermosa Beach, CA
Programming Experience
3-5
I'm making my own user control, and I want it to act like a container at design. Basically the control is doing some custom draw code, and also contains a normal Panel. So now, when I put my control onto my Form at design time, I will obviously want to be able to drag other controls into my control, similar to the way a panel works. I.e. it will generate the code behind the scenes to do the appropriate mycontrol.Panel1.Controls.Add call against whatever object.

Thanks for any suggestions or ideas...
 
Inheriting your class from Panel instead of UserControl is not an option?
 
Eh...Not really, unless you have some suggestions. I have a UserControl that is drawn as two separate parts. The top part is a sort of title bar, and the bottom part is the Panel area where clients can drop whatever they want into it. Plus there's some extra drawing around the actual panel area. So I wrote it as a userControl that contains two separate controls, the titlebar, and the panel.

So I'm wondering what the Panel class does, in terms of attributes or whatever, that allows the designer to auto-generate code in the InitializeComponent() function inside of the form1.designer.vb file.
 
Here's a start using a ControlDesigner, this code was translated from some C# posts I found, not all happy with the behaviour regarding UC panel can be moved around and snapping of controls to the panel, but haven't had time to research it further. Here's the code added to the UserControl:
VB.NET:
Imports System.Windows.Forms.Design
Imports System.ComponentModel

<Designer(GetType(MyPanelControlDesigner))> _
Public Class UserControl1

    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public Property MyPanel() As Panel
        Get
            Return Me.Panel1
        End Get
        Set(ByVal value As Panel)
            Me.Panel1 = value
        End Set
    End Property

End Class
And the inherited ControlDesigner class:
VB.NET:
Public Class MyPanelControlDesigner
    Inherits ParentControlDesigner

    Public Overrides Sub Initialize(ByVal component As IComponent)
        MyBase.Initialize(component)
        Dim ctl As UserControl1 = component
        Me.EnableDesignMode(ctl.MyPanel, "MyPanel")
    End Sub

End Class
 
Back
Top