Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Component added to an Component

13 views
Skip to first unread message

Jon

unread,
Apr 10, 2003, 11:51:27 AM4/10/03
to
Note that in this posting, overused word "Component" means the code generated when you do a "add Component" to a project.

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?


Elan Zhou(MSFT)

unread,
Apr 11, 2003, 3:44:36 AM4/11/03
to
Hi,

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

Jon

unread,
Apr 11, 2003, 10:19:23 AM4/11/03
to
Sorry, my question was not clear.
Note that the question has nothing to do with adding "controls", but with adding "System.ComponentModel.Component"s.

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...

Elan Zhou(MSFT)

unread,
Apr 14, 2003, 8:17:56 AM4/14/03
to
You can also override the Dispose method in the Component in a similar way
though such code is not generated automatically when components are dragged
to the Component Design Surface.
0 new messages