简体   繁体   English

单击按钮上的停靠面板C#

[英]Dock Panel on Button Click C#

I'm using WinForms. 我正在使用WinForms。 In my form i have 2 panels which i want to dock up or down on button click. 在我的表单中,我有2个面板,我希望在单击按钮时向上或向下停靠。

The issue i'm running into is that my panels is not docking correctly. 我遇到的问题是面板没有正确对接。 When i click on the up button, panel one label gets covered by panel2. 当我单击向上按钮时,面板1的标签被panel2覆盖。

Panel 1: (Anchor: Top, Left, Right) 面板1 :(锚点:顶部,左侧,右侧)

Panel 2: (Anchor: Top, Bottom, Left, Right) 面板2 :(锚点:顶部,底部,左侧,右侧)

    private void Up_Btn_Click(object sender, EventArgs e)
    {
        panel1.Dock = System.Windows.Forms.DockStyle.Fill;

        panel2.Dock = System.Windows.Forms.DockStyle.Top;
    }

    private void Down_Btn_Click(object sender, EventArgs e)
    {
        panel1.Dock = System.Windows.Forms.DockStyle.Fill;

        panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
    }

Incorrect the label should not be covered by the panels 标签不正确,面板上不得覆盖标签

在此处输入图片说明

What supposed to happen when Up button is clicked 单击“向上”按钮时应该发生什么

在此处输入图片说明

What supposed to happen when Down button is clicked 单击向下按钮时应该发生什么

在此处输入图片说明

public Form1()
{
    InitializeComponent();
    panel1.BringToFront();
}

private void Up_Click(object sender, EventArgs e)
{
    panel1.Dock = DockStyle.Fill;
    panel2.Dock = DockStyle.Top;
}

private void Down_Click(object sender, EventArgs e)
{
    panel1.Dock = DockStyle.Fill;
    panel2.Dock = DockStyle.Bottom;
}

The trick is to correct the order of the controls. 技巧是更正控件的顺序。

See here: Docking multiple controls - one fills remaining space 请参阅此处: 对接多个控件-一个可填充剩余空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM