: The result reported here is a hypothesis
based on testing in Visual Studio Pro 2010, with the WinForms project set to compile against .NET FrameWork 4 Client Profile, only.
: This tip does not consider using Component Classes which are sub-classed as Containers. Only
is discussed here.
: I appreciate all feedback, and correction, on the content of this Tip: hypothesis refutation welcome.
0. Consider the action of drag-dropping a Control from the ToolBox onto a Panel, or GroupBox, on a Form at DesignTime: you will get visual feedback from the drop target, and the dropped Control will become a child of the
However, if you create a
in a WinForms .NET solution, and then build the project, and then drag-drop an instance of the
: it will not 'accept' ('swallow' may be a better term)other Controls: in other words, the drag-dropped Controls will not become 'child' controls of the
: rather, they will become 'child' Controls of the Form. And you do not have any visual feedback as you do when you drag-drop to a
, or other Container Control.
- An early Microsoft tech-note(1)[^] showed how to make a
DesignTime in a Windows Form 'accept' Controls drag-dropped from the ToolBox. This was accomplished by using the
- In 2009, Henry Minute published a CodeProject article(2)[^] addressing the problem that a UserControl placed on a Windows Form at DesignTime inside another UserForm (i.e., nested) could not have new controls drag-dropped to it from the Visual Studio Toolbox, and have the
UserControl 'accept' these dragged Controls as 'child' controls of the
UserForm: these dragged Controls would remain 'child' controls of the Parent Form.
Something appears to have changed in VS 2010
0. adorning a
Attribute like this:
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
public partial class yourUserControl: UserControl
- As expected (based on the Microsoft tech-note cited: (1)): you now will find that you can drag-drop other Controls onto the top-level UserForm at DesignTime, and get DesignTime feedback.
- What is not expected: you can nest instances of this
UserControl inside other instances of this
UserControl, and you will still be able to drag-drop new Controls from the ToolBox onto the nested
UserControls, and get Design-Time feedback, as if you were drag-dropping.
- What is also not expected: you can drag-drop a Control onto the Form surface, and then move it inside a top-level or nested
UserControl adorned with the
IDesigner Attribute, and it will be automatically 're-Parented:' however, you will not get the Design-Time drag-feedback you do when you drag-drop from the 'ToolBox.
VS 2010 Pro, Windows Forms, now makes it easier to deal with DesignTime support ... via drag-drop of Controls from the ToolBox ... of nested
s without going to the lengths that Henry Minute went to in 2009 ... of implementing some complex DesignerProvider code ... in his excellent CodeProject article cited here(2).