예제 #1
0
        public virtual bool AddControl(IControl control)
        {
            System.Diagnostics.Debug.Assert(control != null, "Can not add a null control");

            // Adding a control to itself or to a child of itself
            // will unravel the very fabric of the universe
            for (IControl parent = this; parent != null; parent = parent.Parent) {
                if (parent == control)
                    throw new InvalidOperationException("Can not add a Control to itself, or to any children of itself.");
            }

            //_layoutAndAlignChild(control);
            if (!_lockControlList()) {
                control.Close();
                Console.Error.WriteLine("Could not acquire control lock, control discarded.");
                return false;
            }
            try {
                _controls.Add(control);
            } finally {
                _unlockControlList(true);
            }
            control.SetParent(this);
            control.OnResized += this._handleResizeEvent;
            control.OnClosed += this._handleClosedEvent;
            _layoutAndAlignChildren();
            return true;
        }
예제 #2
0
        public bool RemoveControl(IControl control)
        {
            Debug.Assert(control != null, "Can not remove a null control");
            if (!_controlLayers.TryRemove(control))
                return false;

            control.OnClosed -= _closedControlHandler;
            control.Close();

            return true;
        }