Results 1 to 7 of 7

Thread: Disable Container Control [Resolved]

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Resolved Disable Container Control [Resolved]

    How do you disable a container control, like a panel control, from allowing the addition of other child
    controls to it?

    Thanks
    Last edited by RobDog888; Apr 15th, 2005 at 03:00 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Disable Container Control

    You have to create a custom Designer for the Panel, which inherits the ParentControlDesigner class.
    Then you can override the CanParent method to restrict the controls that can
    be added to the Panel via the designer.

    To prevent runtime additions, you'll have to create a custom ControlsCollection
    and override the Add method to throw an exception when an invalid control is added, i.e.
    VB Code:
    1. Imports System.ComponentModel
    2. Imports System.Windows.Forms.Design
    3.  
    4. ' Assign the Designer for this Control
    5. <Designer(GetType(MyPanelDesigner))> _
    6. Public Class MyPanel
    7.    Inherits Panel
    8.  
    9.    ' Override the CreateControlsInstance to return our custom ControlsCollection
    10.    Protected Overrides Function CreateControlsInstance() As System.Windows.Forms.Control.ControlCollection
    11.       Return New MyPanelControlCollection(Me)
    12.    End Function
    13. End Class
    14.  
    15. ' Custom ControlsCollection, that prevents anything
    16. ' but Labels from being added
    17. Public Class MyPanelControlCollection
    18.    Inherits Control.ControlCollection
    19.  
    20.    Public Sub New(ByVal owner As Control)
    21.       MyBase.New(owner)
    22.    End Sub
    23.  
    24.    Public Overrides Sub Add(ByVal value As System.Windows.Forms.Control)
    25.       If Not value.GetType() Is GetType(Label) Then
    26.          Throw New ArgumentException("Only Labels Allowed!")
    27.       End If
    28.       MyBase.Add(value)
    29.    End Sub
    30. End Class
    31.  
    32. ' ParentControlDesigner that prevents anything but
    33. ' labels from being added to the control in the Designer
    34. Public Class MyPanelDesigner
    35.    Inherits ParentControlDesigner
    36.  
    37.    Public Overloads Overrides Function CanParent(ByVal control As System.Windows.Forms.Control) As Boolean
    38.       If control.GetType() Is GetType(Label) Then
    39.          Return True
    40.       End If
    41.       Return False
    42.    End Function
    43. End Class
    Regards,

    - Aaron.

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Disable Container Control

    's Aaron.

    One other question is if the LinkLabels are required to be public class then the user could add a LL manually to the subpanel?
    There will be a duplicate "design structure" of the Panels for the LinkLabels too.

    Ps, I already finished the property updates to both the UC and the SubPanels. Working on adding the
    LinkLabel Headers and changing the PanelHeaderClick events over to the LL Headers.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Disable Container Control

    It depends on what you "want" it to do, if you don't want to allow the user to manually add "Link Labels",
    Then you could derive your own class from the LinkLabel and only allow that and not make it publicly available.

    Regards,

    - Aaron.

  5. #5

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Disable Container Control

    Yes, I have a class that is Inheriting from the LinkLabel control. Now this inherited class will also have the
    related collection class. In order for the UITypeEditor to display the LLs they need to be Public so if preventing
    the user from adding other controls works with the code you posted then the LL class will also show since its Public
    and they can add those to the control manually which is what I dont want.

    Like the Tab control, you can not add tabs from the toolbox nor see them, but through the designer you can
    add them. This is what I need to replicate.

    Thanks,
    Robert
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Disable Container Control

    Ok, I got the code implemented but I made a modification so I can only allow two types of controls.
    One, the SubPanels and two, the about label.

    VB Code:
    1. Public Class MyMainPanelControlCollection
    2.  
    3.     Public Overrides Sub Add(ByVal value As System.Windows.Forms.Control)
    4.         If Not value.GetType() Is GetType(MySubPanel) And Not value.GetType() Is GetType(MyUC.About.AboutLabel) Then
    5.             Throw New ArgumentException("Only MySubPanels Allowed!")
    6.         End If
    7.         MyBase.Add(value)
    8.     End Sub
    The code is working great!

    Thanks,
    Robert
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: Disable Container Control [Resolved]

    RobDog888 do you have a finished example for this project? I am deperately trying to do something similar in VS 2005. Scoured the web and this site with not much luck.

    Thanks,

    Christian
    In life you can be sure of only two things... death and taxes. I'll take death.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width