Sign in to follow this  
Daniel Miller

[.net] IContainer

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this