How to make a docked panel go overtop of another docked panel

1.4k Views Asked by At

I have a panel that is docked to the left and another panel that is docked as fill in the middle. my panel on the left starts out with a width of 8 and then it slides open to 295. I need it to go over top of the panel. What it is doing is shoving the entire panel over? Is there any way to get it to go over top of the panel?

2

There are 2 best solutions below

0
On BEST ANSWER

What I ended up doing was moving the bringtofront function after the panel had been added. I didnt realize I was doing it before the panel was being added to the window.

0
On

Leave your left panel docked and instead of docking the other one, size it to the initial client area anchor it on top, bottom, left and right. Then to make sure things happen in the right order, right-click on the left panel and select Bring To Front.

Here's the designer code:

        // 
        // panelLeft
        // 
        this.panelLeft.BackColor = System.Drawing.SystemColors.GradientActiveCaption;
        this.panelLeft.Dock = System.Windows.Forms.DockStyle.Left;
        this.panelLeft.Location = new System.Drawing.Point(0, 0);
        this.panelLeft.Name = "panelLeft";
        this.panelLeft.Size = new System.Drawing.Size(54, 456);
        this.panelLeft.TabIndex = 0;
        this.panelLeft.Click += new System.EventHandler(this.PanelLeftClick);
        // 
        // panelOther
        // 
        this.panelOther.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
        | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this.panelOther.BackColor = System.Drawing.Color.Maroon;
        this.panelOther.Location = new System.Drawing.Point(60, 0);
        this.panelOther.Name = "panelOther";
        this.panelOther.Size = new System.Drawing.Size(477, 456);
        this.panelOther.TabIndex = 1;

And the form handler code that shows the management. (Click on the left panel either makes it large or small...)

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1() {InitializeComponent();}

        private bool _isLeftPanelBig;
        private void PanelLeftClick(object sender, EventArgs e)
        {
            panelLeft.Size = _isLeftPanelBig ? new Size(80, 300) : new Size(500, 300);

            _isLeftPanelBig = !_isLeftPanelBig;
        }
    }
}