Make Container UserControl force controls to be added to a child container control

  • Thread starter Thread starter Codemonkey
  • Start date Start date
C

Codemonkey

Hi,

I'm writing a container usercontrol. It consists of two panels. The first
panel is designed to act as a titlebar for the usercontrol. I want the
second panel to become the place where other controls are contained when
dropped on to it from a form designer (so they can never be positioned on
top of the title).

Is there any way of fooling the windows forms designer into adding contained
controls into the second panel, instead of the usercontrol itself?

I appreciate any help anyone can give me.

Thanks,

Trev.
 
Hello CodeMonkey

What you are trying to do is kind of advanced, you would need to assign a
designer to your usercontrol as follows.

[Designer(typeof(ParentControlDesigner))]
public class UserControl1 : System.Windows.Forms.ContainerControl
{
....
}

This would make your entire control editable in the Forms editor.

To make a small sub section of the control editable you could derive your
own custom designer from ParentControlDesigner and overload the drag drop
events. Checking the DragEventArgs parameter for what the current mouse
co-ordinates are and deciding wether or not you will allow the drop to
take place. I have not tried it myself and it may not work.

Someone who has worked with designers a lot more could help you better
perhaps you should repost in
microsoft.public.dotnet.framework.windowsforms.designtime

I tried creating a newly derived class from panel with the designer
attribute attached but it didn't work. I think because this derived panel
was not having code generated for it in the actual form. That would be
another avenue of exploration (Maybe???).
 
Thanks for the tips, Luke.

I've reposted in microsoft.public.dotnet.framework.windowsforms.designtime
along with what I've found using your drag-drop tips.

Cheers again,

Trev.



Hello CodeMonkey

What you are trying to do is kind of advanced, you would need to assign a
designer to your usercontrol as follows.

[Designer(typeof(ParentControlDesigner))]
public class UserControl1 : System.Windows.Forms.ContainerControl
{
....
}

This would make your entire control editable in the Forms editor.

To make a small sub section of the control editable you could derive your
own custom designer from ParentControlDesigner and overload the drag drop
events. Checking the DragEventArgs parameter for what the current mouse
co-ordinates are and deciding wether or not you will allow the drop to
take place. I have not tried it myself and it may not work.

Someone who has worked with designers a lot more could help you better
perhaps you should repost in
microsoft.public.dotnet.framework.windowsforms.designtime

I tried creating a newly derived class from panel with the designer
attribute attached but it didn't work. I think because this derived panel
was not having code generated for it in the actual form. That would be
another avenue of exploration (Maybe???).
 
Back
Top