Pabo.MozBar.MozPane.OnControlAdded C# (CSharp) Method

OnControlAdded() protected method

protected OnControlAdded ( System.Windows.Forms.ControlEventArgs e ) : void
e System.Windows.Forms.ControlEventArgs
return void
        protected override void OnControlAdded(ControlEventArgs e)
        {
            // check if control is a MozItem
            if ((e.Control as MozItem) == null)
            {
                // If not remove and...
                this.Controls.Remove(e.Control);
                // throw exception
                throw new InvalidCastException("Only MozItem's can be added to the MozPane");
            }

            base.OnControlAdded(e);

            // Check if item exists in collection
            if (!this.Items.Contains((MozItem) e.Control))
            {
                // if not add it
                this.Items.Add((MozItem) e.Control);
            }

            // Refresh
            Invalidate();
        }