System.ComponentModel.Container.Add C# (CSharp) Method

Add() public method

Adds the specified component to the and assigns a name to it.

public Add ( IComponent component, String name ) : void
component IComponent
name String
return void
        public virtual void Add(IComponent component, String name)
        {
            lock (_syncObj)
            {
                if (component == null)
                {
                    return;
                }

                ISite site = component.Site;

                if (site != null && site.Container == this)
                {
                    return;
                }

                if (_sites == null)
                {
                    _sites = new ISite[4];
                }
                else
                {
                    // Validate that new components
                    // have either a null name or a unique one.
                    //
                    ValidateName(component, name);

                    if (_sites.Length == _siteCount)
                    {
                        ISite[] newSites = new ISite[_siteCount * 2];
                        Array.Copy(_sites, 0, newSites, 0, _siteCount);
                        _sites = newSites;
                    }
                }

                if (site != null)
                {
                    site.Container.Remove(component);
                }

                ISite newSite = CreateSite(component, name);
                _sites[_siteCount++] = newSite;
                component.Site = newSite;
                _components = null;
            }
        }

Same methods

Container::Add ( IComponent component ) : void

Usage Example

 protected FormLog()
 {
     InitializeComponent();
     repaintTimer = new Timer { Interval = 1000 };
     components = new Container();
     components.Add(repaintTimer);
     repaintTimer.Tick += (s, e) => UpdateLines();
     instance = this;
 }
All Usage Examples Of System.ComponentModel.Container::Add