[.net] IContainer

Started by
1 comment, last by Daniel Miller 18 years, 9 months ago
MSDN's description is about as generic as can be: IContainer
Quote:Containers are objects that encapsulate and track zero or more components. In this context, containment refers to logical containment, not visual containment. You can use components and containers in a variety of scenarios, including scenarios that are both visual and not visual. Notes to Implementers: To be a container, the class must implement the IContainer interface, which supports methods for adding, removing, and retrieving components.
Could someone explain it a little better? Also, is this what a Windows Form uses to store child conrols?
Advertisement
For an example see the Container class. (It's just a container; nothing to explain about)

Regarding ChildControls:
The WinForms designer uses two 'containers'.
1. 'Normal' controls like Buttons, Labels etc. are kept as instance variables (Protected Fields) of the form.
2. Controls that need their member Dispose being called on the closing of the form (e.g.: Timer) are stored in the previous way AND are kept in a Container class. The container class calls Dispose on its contained items.

Just drag a button and a timer control on a form and look at the generated code...

Cheers
Thanks. [grin]

This topic is closed to new replies.

Advertisement