Question Restricting controls added to a container in the designer

Bufedog

Member
Joined
Nov 20, 2006
Messages
16
Programming Experience
1-3
I am making a multipanel control, and I want to be able to restrict the controls that can be added to it (only panels added to the control).

How can I do this, since I have absolutely no Idea?

Thanks in advance for your help.

Chuck
 
Write a class that inherits some ParentControlDesigner class and override the CanParent method. Use DesignerAttribute to assign this designer to your multipanel class. Example:
VB.NET:
<System.ComponentModel.DesignerAttribute(GetType(PanelingScrollableControlDesigner))> _
Public Class Paneling
    Inherits Panel

End Class

Public Class PanelingScrollableControlDesigner
    Inherits System.Windows.Forms.Design.ScrollableControlDesigner

    Public Overrides Function CanParent(ByVal control As System.Windows.Forms.Control) As Boolean
        If TypeOf control Is Panel Then
            Return MyBase.CanParent(control)
        Else
            Return False
        End If
    End Function

End Class
ScrollableControlDesigner here in turn inherits ParentControlDesigner and is used by the default Panel class.
You have to reference System.Design.dll to use these classes.
 
Back
Top