UserControls as Containers
-
Hi, Can you help ? I don't know how to phrase my question so I have written it out in serveral different ways. They all make sense to me but that is because I know what I want! And the question ? ....... If I inherit from a System.Windows.Forms.ContainerControl I can use the inherited control as a container type control within the IDE, and drag-drop toolbox items into it. However if I inherit from a UserControl, the the ability to drag-drop controls into it seems to be disabled. What I am attempting to do is create a container control that can be drag-dropped onto a form and be used as any normal container control (eg. Panel). To do this I can inherit from the ContainerControl and all is well. As an extension to this I would also like to be able to inherit directly from the control and use it as a designer base. If I inherit from a UserControl, then I can use the default usercontrol designer, but I cannot then use the created control on a Form, and drag-drop toolbox items into it. Is there anyway of creating a container control, which is based on a UserControl, and use the created control within the IDE in the sameway as all the built-in container controls. Gary Ranson.
-
Hi, Can you help ? I don't know how to phrase my question so I have written it out in serveral different ways. They all make sense to me but that is because I know what I want! And the question ? ....... If I inherit from a System.Windows.Forms.ContainerControl I can use the inherited control as a container type control within the IDE, and drag-drop toolbox items into it. However if I inherit from a UserControl, the the ability to drag-drop controls into it seems to be disabled. What I am attempting to do is create a container control that can be drag-dropped onto a form and be used as any normal container control (eg. Panel). To do this I can inherit from the ContainerControl and all is well. As an extension to this I would also like to be able to inherit directly from the control and use it as a designer base. If I inherit from a UserControl, then I can use the default usercontrol designer, but I cannot then use the created control on a Form, and drag-drop toolbox items into it. Is there anyway of creating a container control, which is based on a UserControl, and use the created control within the IDE in the sameway as all the built-in container controls. Gary Ranson.
You can get a start by adding a reference to System.Design.dll and adding the following attribute to your UserControl
[Designer(typeof(System.Windows.Forms.Design.ParentControlDesigner))]
You may want to put some code into the Paint event so that you draw a border around the control if DesignMode is true; otherwise the control will blend into the form with the default values. James "And we are all men; apart from the females." - Colin Davies