When you drag a component to the design surface of a Form, code is emitted that:
1) A local instance is created
2) It is added to the local component container.
3) It is disposed, when the Form is disposed.
When you drag a component to the design surface of a Component, code is emitted that:
1) A local instance is created
2) It is NOT added to the local component container.
3) It is NOT disposed, when the parent Component is disposed.
In fact, I can not see any use for the "component container variable" in a Component.
Is this a feature that I do not understand, or is it a bug?
Suppose you drag a GroupBox control onto a WinForm and then drag a Button
control onto the GroupBox control. Then, if you check the
InitializeComponent() method generated by the Windows Form Designer, you
will find the code similar to the following which relates the Button
control to the GroupBox control.
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[]
{this.button1});
Regards,
Elan Zhou
This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com
In a Form (i.e. a class derived from System.Windows.Forms.Form ):
1) There is generated code to Dispose of the components in the "this.components" container.
In a Component (i.e. a class derived from System.ComponentModel.Component ):
1) There is NO generated code to Dispose of the components in the "this.components" container.
Hence:
Components (I am not talking about controls here) that are added by dragging to a Form Design Surface, are disposed when the parent
form is disposed.
Components that are added by dragging to a Component Design Surface, are NOT disposed when the parent component is disposed.
I do not understand why the Form's components are disposed differently that a Component's components?
Is my concern stated more clearly this time?
"Elan Zhou(MSFT)" <yxz...@online.microsoft.com> wrote in message news:FW5U44$$CHA...@cpmsftngxa06.phx.gbl...