2

我有一个停靠在左侧的面板和另一个停靠在中间的面板。我左边的面板以 8 的宽度开始,然后滑开到 295。我需要它越过面板的顶部。它在做什么是将整个面板推倒?有没有办法让它越过面板顶部?

4

2 回答 2

1

让您的左侧面板停靠,而不是停靠另一个面板,将其调整为初始客户区域的大小,将其锚定在顶部、底部、左侧和右侧。然后为了确保事情以正确的顺序发生,右键单击左侧面板并选择置于前面。

这是设计器代码:

        // 
        // 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;

以及显示管理的表单处理程序代码。(单击左侧面板使其变大或变小...)

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;
        }
    }
}
于 2011-10-05T15:44:14.120 回答
0

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.

于 2011-10-19T13:22:45.953 回答