Dropping controls in a User Control ges added to parent control

J

Joe

Hello all,

When I drop a control (say a Button) on my user control, the button is added
to the parent control of my user control and not my control. For example if
my user control is on a panel and a drop a button on it, the button is added
to the panel.Controls. I tried Bring to Front but it didn't make a
difference.

What am I doing wrong?

-Joe
 
L

Lars-Inge Tønnessen \(VJ# MVP\)

I have seen lots of strange behaviour with the design viewer when working
with a lot of panels.
Please add the button in code.

userControl.Controls.Add(Your_button_here);


Regards,
Lars-Inge Tønnessen
 
T

Tim Wilson

AFAIK, the UserControl is not intended to be a container at design-time when
placed on a Form. In other words, the UserControl acts as a container when
you're designing the UserControl itself; however, it acts as a normal
control when dropped onto the design surface of a Form. So what is happening
in your situation is that you're attempting to add the Button to the
UserControl, which is not acting as a container, and so the Button will be
added as a sibling to the UserControl within the parent. You can change this
behavior by specifying the ParentControlDesigner class as the Designer to
use for your custom UserControl.
http://msdn2.microsoft.com/en-us/library/system.windows.forms.design.parentcontroldesigner.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top