Jeff, How do you expect the framework to draw your control if it can't get to the controls it's comprised of?
I think that sums it up in a nutshell. If you're creating a composite control, the framework (and everyone else, for that matter) needs access to the Controls collection so it can tell those controls to draw themselves. There are dozens of ways around this, based on your requirements. For your name control, it would be _easiest_ to draw the thing yourself by overriding Render and either writing out the HTML yourself or creating the controls then. If your controls are more complex, you may want to go a different route. If that's the case, feel free to post in more detail. HTH, -jk -----Original Message----- From: dotnet discussion [mailto:[EMAIL PROTECTED]] On Behalf Of Jeff Sent: Saturday, May 11, 2002 11:50 AM To: [EMAIL PROTECTED] Subject: [DOTNET] Usercontrol Encapsulation Member Hiding Question I'm probably in a hurry and missing something obvious, but I'm having trouble encapsulating everything I need to in a user control. Suppose I have a UserControl consisting of 3 textboxes (First, Middle, and Last Name, for instance). I have nice layout and validation logic contained within the control. It is supposed to be a black box, a closed component. As a simple first example, I use proper encapsulation techniques to expose 3 properties (FirstNameText, MiddleNameText, and LastNameText) that access the Text properties of the 3 textbox controls contained in the usercontrol. I would certainly expose a few more later, but this will suffice for example. I DO NOT expose 99% of the properties about the textboxes on purpose, of course. Now, the darn Controls collection destroys all that by giving the parent form all the access in the world to the constituent textboxes on the usercontrol. Why bother having "private" as the default modifier for controls if you open the door to chaos with the Controls collection? I can't turn it off. Heck, the parent form can Add, Remove, or even worse Clear the Controls collection of the user control. This sucks badly. I have tried to use name hiding to change the level of the Controls collection to private in the UserControl so that the UserControl itself could reference it as this.Controls instead of always having to use base.Controls. //following code in the UserControl is useless [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new private Control.ControlCollection Controls { get { return base.Controls; } } This was to no avail..it still is public accessible to the outside world. The form that is hosting the UserControl can still get to the collection and screw around with the individual textboxes within the UserControl. Heck, not only is the Controls collection still public to the hosting form, but the stupid EditorBrowsable property seems to be ignored and you can see the Controls collection member in IntelliSense when you hit the dot. So, does anyone know how to hide this stinking collection so you can actually make a stable component that doesn't expose it's innards to parents that consume it? This is chaos if you can't turn it off. Why bother with those private controls and good practice accessors, forget OOP and just expose the whole friggin world as public like in old VB if you have to have a public Controls collection always. There has to be a way to secure your constituent controls, hasn't there? I hope I'm missing the forest for the trees or something here. Thanks, Jeff You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.