Export (0) Print
Expand All

Creating Component Containers

A component container is a specialized class that acts as a means of organizing and containing components. Through a container you can track your components, communicate with them via the Site that hosts the component, and provide a means of common disposal after they are no longer needed. For details, see Containers, Sites, and Components.

To create a component container

  1. Declare a variable of the type System.ComponentModel.Container, or any class that implements the IContainer interface.
    ' Visual Basic
    Dim myContainer as System.ComponentModel.Container
    
    //C#
    System.ComponentModel.Container myContainer;
    
  2. Create an instance of the container class in your variable.
    ' Visual Basic
    myContainer = New System.ComponentModel.Container()
    
    // C#
    myContainer = new System.ComponentModel.Container();
    
  3. Call the Container.Add and Container.Remove methods to add and remove components to and from your container.
    ' Visual Basic
    myContainer.Add(myComponent)
    myContainer.Remove(myComponent)
    
    // C#
    myContainer.Add(myComponent);
    myContainer.Remove(myComponent);
    

See Also

Containers, Sites, and Components | Communication Between Containers and Components | Extending Component Containers | Container Class

Show:
© 2014 Microsoft