Click here to Skip to main content
11,934,199 members (37,078 online)
Rate this:
Please Sign up or sign in to vote.
Dear friends

I create an UserControl which has a groupBox and a checkBox in the corner.
The Purpose is to enable/disable the controls in the groupBox when checkBox.Checked changes.

My problem is:

When I add an instance of drag an userControl on a Form, the controls that I add to it, won't place in groupBox.Controls collection.

Please help me friends. I know it doesn't make scene but really it happened.
Posted 28-Jul-12 13:21pm
Edited 28-Jul-12 14:52pm
Wes Aday 28-Jul-12 20:17pm
Probably because when your user control is on the form the groupbox cannot get brought forward so that controls can be added to it.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

1 - this makes no sense. NEVER make controls public, expose properties to change the things you want to allow. But, if it's enabled or not has nothing to do with class modifiers

2 - If you add controls on to the groupbox, then they will be inside your control, not inside the form that holds them, surely ?
Christian Graus 28-Jul-12 19:04pm
To the degree that you asked a question, this is the answer.
Christian Graus 28-Jul-12 20:04pm
I am confused. I told you what I reckon is happening. Your user control gets dragged on to the form as one object. Any other control you add to that user control inside a form, gets added to the form, not the user control. therefore it can't be added to the groupbox in the user control, you need to do that to the control, not the form that has the control on it.
Christian Graus 28-Jul-12 20:19pm
If you're adding a control to a user control, then you would write code to work with it in the user control, not in the main window you're working with. So, it makes perfect sense that you add controls to a user control when designing it, and add controls as siblings of your user control, when you drag the user control in to a window or control you are working with.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 28 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100