Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I tried to make a custom usercontrol which is derieved from toolbox and listview, I need to create instances of this control by dragging to form then add different toolbox items according to circumstance at design time.
I wanted to click onto the subcontrol in the control and modify its properties.

Is there a way to achieve this?

Your reply will be appreciated.
Posted
Updated 18-Oct-13 5:35am
v2

That's not how a Custom control is meant to work, but you can do it - all you need to do is create a Container control. MSDN can help: http://support.microsoft.com/kb/813450[^]
 
Share this answer
 
Comments
Emre Ataseven 18-Oct-13 12:56pm    
Oh i get the point. Thank you.
OriginalGriff 18-Oct-13 14:01pm    
You're welcome!
BillWoodruff 18-Oct-13 20:49pm    
***** Nailed that one.
I think you have the correct answer from OriginalGriff; if you want to see some previous discussion of this issue here on CodeProject:

July 2009 CP article: "Designing Nested Controls" by Henry Minute: [^].

July 2011 CP Tip/Trick: "DesignTime adding of Controls to a UserForm on a WinForm" by Bill Woodruff: [^]

What many people do not realize (pointed out in my 2011 Tip) is that by use of that simple Attribute before a UserControl's Class definition you can enable nesting ... to any depth ... of Controls, and other UserControls, inside the modified UserControl.

Yes, you can even have nested instances of the modified UserControl itself inside the modified UserControl.

However, the question arises: do you really want to take advantage of such "freedom:" does use of this type of nesting of Controls result in good OO design, given your task at hand, and the possible issues of future maintenance of your code ?

All the Controls you may have added to an instance of a UserControl on a Form at design-time remain "bound" to the application you are creating: i.e., they are not re-usable.

If you want your modified UserControl to be re-usable: I propose you consider (the slow and steady approach ?):

1. define your "base" UserControl

2. as the need arises to create other variants of the base UserControl: create a new UserControl, and make it inherit from the base UserControl.

If you do this, note:

1. Any Controls on the base UserControl will now, of course, appear on the inherited UserControl, but they will be locked.

If you have Button on UserControl1 with a Click EventHandler, and you then sub-class UserControl1 to create UserControl1a: a Click on the Button in UserControl1a will fire the Click EventHandler in UserControl1.

2. If the base UserControl was decorated with the Attribute that allows it function as a Container at design-time, the inherited UserControl will also have that ability: no need to also write that Attribute in the inherited UserControl.

3. as you might expect, you can add new Controls of any Type to the inherited UserControl, and they do not affect the base UserControl in any way.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900