Ejemplo n.º 1
0
        private void AddControl(DockingControl control, int dockIndex, int dimension)
        {
            Manager.SuspendLayout();

            if (!_mapDockingControlToData.ContainsKey(control))
            {
                DockingControlData dockingControlData = new DockingControlData(null,
                                                                               new AutoHideChangedHandler(DockingControl_AutoHideChanged),
                                                                               new CancelledChangedHandler(DockingControl_CancelledChanged));

                _mapDockingControlToData.Add(control, dockingControlData);

                control.AutoHideChanged  += dockingControlData.AutoHideChangedHandler;
                control.CancelledChanged += dockingControlData.CancelledChangedHandler;
            }

            switch (Dock)
            {
            case DockStyle.Left:
            case DockStyle.Right:
                if (_dockingControls.Count == 0)
                {
                    this.Width = Math.Min(MaxInitialDockSize, PaddingWidth + dimension);
                }

                break;

            case DockStyle.Top:
            case DockStyle.Bottom:
                if (_dockingControls.Count == 0)
                {
                    this.Height = Math.Min(MaxInitialDockSize, PaddingWidth + dimension);
                }

                break;
            }

            if (dockIndex < 0 || dockIndex >= _dockingControls.Count)
            {
                AddControlHelper(control, _dockingControls.Count);
            }
            else
            {
                AddControlHelper(control, dockIndex);
            }

            Manager.ResumeLayout(true);

            CheckVisibility();
        }
Ejemplo n.º 2
0
        private void CancelControl(DockingControl control)
        {
            DockingControlData data = _mapDockingControlToData[control];

            if (control.Cancelled)
            {
                if (data.Button == null)
                {
                    if (_dockingControls.GetVisibleDockedControlCount() == 0)
                    {
                        this.Visible = false;
                    }
                }
                else
                {
                    ToolStripButton button = _mapDockingControlToData[control].Button;
                    button.Visible = false;

                    AutoResizeControl autoResizeControl = _mapButtonToControl[button];
                    autoResizeControl.Visible = false;

                    if (ToolStripHelpers.GetVisibleButtonCount(_menuStrip) == 0)
                    {
                        _menuStrip.Visible = false;
                    }
                }
            }
            else
            {
                ToolStripButton button = _mapDockingControlToData[control].Button;

                if (button == null)
                {
                    this.Visible = true;
                }
                else
                {
                    button.Visible     = true;
                    _menuStrip.Visible = true;
                }
            }
        }
Ejemplo n.º 3
0
        public void RemoveControl(DockingControl control)
        {
            Manager.SuspendLayout();

            DockingControlData data = _mapDockingControlToData[control];

            control.AutoHideChanged  -= data.AutoHideChangedHandler;
            control.CancelledChanged -= data.CancelledChangedHandler;

            _mapDockingControlToData.Remove(control);

            if (data.Button != null)
            {
                _mapButtonToControl.Remove(data.Button);
            }

            _dockingControls.Remove(control);
            OnDockingControlRemoved(control);

            CheckVisibility();

            Manager.ResumeLayout(true);
        }
Ejemplo n.º 4
0
        private void AutoHideControl(DockingControl control)
        {
            DockingControlData oldData = _mapDockingControlToData[control];

            if (oldData.Button == null)
            {
                Manager.SuspendLayout();

                _menuStrip.Visible = true;

                ToolStripButton button = new ToolStripButton(control.Title);
                button.MouseHover += new EventHandler(button_MouseHover);
                button.Click      += new EventHandler(button_Click);
                button.MouseEnter += new EventHandler(button_MouseEnter);
                button.MouseLeave += new EventHandler(button_MouseLeave);
                button.Visible     = !control.Cancelled;
                _menuStrip.Items.Add(button);

                if (_dockingControls.GetVisibleDockedControlCount() == 0)
                {
                    this.Visible = false;
                }

                AutoResizeControl autoResizeControl = new AutoResizeControl(control, this);
                autoResizeControl.Visible = false;
                autoResizeControl.Parent  = this.Parent;

                switch (this.Dock)
                {
                case DockStyle.Bottom:
                    autoResizeControl.DockDirection = DockingType.Bottom;
                    autoResizeControl.Padding       = new Padding(0, PaddingWidth, 0, 0);
                    break;

                case DockStyle.Fill:
                    break;

                case DockStyle.Left:
                    autoResizeControl.DockDirection = DockingType.Left;
                    autoResizeControl.Padding       = new Padding(0, 0, PaddingWidth, 0);
                    break;

                case DockStyle.None:
                    break;

                case DockStyle.Right:
                    autoResizeControl.DockDirection = DockingType.Right;
                    autoResizeControl.Padding       = new Padding(PaddingWidth, 0, 0, 0);
                    break;

                case DockStyle.Top:
                    autoResizeControl.DockDirection = DockingType.Top;
                    autoResizeControl.Padding       = new Padding(0, 0, 0, PaddingWidth);
                    break;

                default:
                    break;
                }

                _mapButtonToControl.Add(button, autoResizeControl);
                _mapDockingControlToData[control] = new DockingControlData(button, oldData.AutoHideChangedHandler, oldData.CancelledChangedHandler);

                control.DraggingEnabled = false;
                control.Visible         = true;

                OnDockingControlAutoHide(control);

                Manager.ResumeLayout(true);
            }
        }
Ejemplo n.º 5
0
        private void ShowControl(DockingControl control)
        {
            Form parentForm = this.ParentForm;

            using (RedrawStopper stopRedraws = new RedrawStopper(parentForm))
            {
                Manager.SuspendLayout();

                switch (this.Dock)
                {
                case DockStyle.Left:
                case DockStyle.Right:
                    this.Width = Math.Max(this.Width, PaddingWidth + control.Width);
                    break;

                case DockStyle.Top:
                case DockStyle.Bottom:
                    this.Height = Math.Max(this.Height, PaddingWidth + control.Height);
                    break;
                }

                this.Visible = true;

                control.Parent = this;

                ToolStripButton button = _mapDockingControlToData[control].Button;

                if (button != null)
                {
                    _menuStrip.Items.Remove(button);

                    AutoResizeControl autoResizeControl = _mapButtonToControl[button];
                    this.Controls.Remove(autoResizeControl);
                    autoResizeControl.Dispose();

                    _mapButtonToControl.Remove(button);
                }

                DockingControlData oldData = _mapDockingControlToData[control];
                _mapDockingControlToData[control] = new DockingControlData(null, oldData.AutoHideChangedHandler, oldData.CancelledChangedHandler);

                if (ToolStripHelpers.GetVisibleButtonCount(_menuStrip) == 0)
                {
                    _menuStrip.Visible = false;
                }

                _dockingControls.Remove(control);
                _dockingControls.Add(control);
                OnDockingControlAutoHide(control);

                if (control.Cancelled)
                {
                    CancelControl(control);
                }

                Manager.ResumeLayout(true);

                control.DraggingEnabled = true;
            }

            control.Focus();
            control.Select();

            if (parentForm != null)
            {
                parentForm.Invalidate(true);
            }
        }