|
-
Apr 14th, 2005, 09:16 PM
#1
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 14th, 2005, 11:39 PM
#2
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:
Imports System.ComponentModel
Imports System.Windows.Forms.Design
' Assign the Designer for this Control
<Designer(GetType(MyPanelDesigner))> _
Public Class MyPanel
Inherits Panel
' Override the CreateControlsInstance to return our custom ControlsCollection
Protected Overrides Function CreateControlsInstance() As System.Windows.Forms.Control.ControlCollection
Return New MyPanelControlCollection(Me)
End Function
End Class
' Custom ControlsCollection, that prevents anything
' but Labels from being added
Public Class MyPanelControlCollection
Inherits Control.ControlCollection
Public Sub New(ByVal owner As Control)
MyBase.New(owner)
End Sub
Public Overrides Sub Add(ByVal value As System.Windows.Forms.Control)
If Not value.GetType() Is GetType(Label) Then
Throw New ArgumentException("Only Labels Allowed!")
End If
MyBase.Add(value)
End Sub
End Class
' ParentControlDesigner that prevents anything but
' labels from being added to the control in the Designer
Public Class MyPanelDesigner
Inherits ParentControlDesigner
Public Overloads Overrides Function CanParent(ByVal control As System.Windows.Forms.Control) As Boolean
If control.GetType() Is GetType(Label) Then
Return True
End If
Return False
End Function
End Class
Regards,
- Aaron.
-
Apr 14th, 2005, 11:51 PM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 15th, 2005, 08:03 AM
#4
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.
-
Apr 15th, 2005, 11:05 AM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 15th, 2005, 02:59 PM
#6
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:
Public Class MyMainPanelControlCollection
Public Overrides Sub Add(ByVal value As System.Windows.Forms.Control)
If Not value.GetType() Is GetType(MySubPanel) And Not value.GetType() Is GetType(MyUC.About.AboutLabel) Then
Throw New ArgumentException("Only MySubPanels Allowed!")
End If
MyBase.Add(value)
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Sep 20th, 2006, 02:05 PM
#7
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|