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

I want to create a UserControl that is made up of three other controls:
- a image in the top left corner
- a label right to the image
- a panel underneath the two other controls

When controls are added to my UserControl after it is created (in designer/runtime), they should not be added to the control itself, but to the panel in the control.

Any ideas how to do that?

Best regards,
Michael
Posted

1 solution

Hello

If my IQ works the best! You mean:

1. A user Control (MyUserControl)
2. Image(MyImage), Label(MyLabel) and Panel(MyPanel) in MyUserControl
3. after creating an instance of the user control, then MyImage and MyLabel must add to MyPanel.

Ok, It's not too hard:

Do it In the Constructor of the MyUserContorl.
For example:

C#
public MyUserControl()
{
    InitializeComponent();

    MyPanel.Controls.Add(MyLabel);
    MyPanel.Controls.Add(MyImage);
}
 
Share this answer
 
v2
Comments
Michael Groeger 13-Apr-12 4:37am    
Thanks for your reply. But no, that is not what I want.

What I want to do is when the control is placed on a form, I want to be able to add controls to MyUserControl's MyPanel. And not to the control MyUserControl itself.

MyImage and MyLabel are just the header of the control. The panel (MyPanel) is a placeholder for other controls.

Best regards,
Michael

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