简体   繁体   English

winforms面板重叠窃听

[英]winforms panels overlapping bugged

Oh wow is this one annoying me. 哦哇这个让我讨厌的哇。 Using c#, winforms, visual studio 2010 ulti. 使用c#,winforms,visual studio 2010 ulti。

Here's my code: 这是我的代码:

private void CheckBoxBranch_CheckedChanged(object sender, EventArgs e)
{   

    if (CheckBoxBranch.Checked == true)
    {
        panelBranch.Visible = true;
        //panelBranch.Parent = null;
        //PanelBuyer.Parent = null;
        //panelBranch.SendToBack();
        //PanelBuyer.SendToBack();
        PanelBuyer.Visible = false;
        CheckBoxBuyer.Checked = false;
        this.Refresh();
    }
    if (CheckBoxBranch.Checked == false)
    {
        panelBranch.Visible = false;
        this.Refresh();
    }

}

private void CheckBoxBuyer_CheckedChanged(object sender, EventArgs e)
{
    if (CheckBoxBuyer.Checked == true)
    {
        panelBranch.Visible = false;
        PanelBuyer.Visible = true;
        CheckBoxBranch.Checked = false;
        this.Refresh();
    }
    if (CheckBoxBuyer.Checked == false)
    {
        PanelBuyer.Visible = false;
        this.Refresh();
    }
}

now this code works fine, no problems, as long as the panels are not on top of each other. 现在这个代码工作正常,没有问题,只要面板不在彼此之上。 When this happens panel-Buyer works fine, Panel-Branch never shows at all. 当发生这种情况时,面板 - 买家工作正常,Panel-Branch根本不会显示。

Now I think this has something to do with the branch panel becoming a child of the buyer panel thus when my logic runs for buyer it applies itself to branch too. 现在我认为这与分支小组成为买方小组的孩子有关,因此当我的买家逻辑运行时,它也适用于分支。

I could transform there positions each time like a rotation but that's a lot of extra code. 我可以像每次旋转那样转换位置,但这是很多额外的代码。

Is there a way to solved this headache nice short sweet and simple one liner? 有没有办法解决这个令人头疼的短而甜的简单的单线眼镜? (I wish). (我希望)。

Make sure one panel is not inside the other panel. 确保一个面板不在另一个面板内。

Easy way to avoid it is by setting the location property manually in the designer. 避免它的简单方法是在设计器中手动设置位置属性。 Do not use the mouse to drag and drop the controls in place. 不要使用鼠标将控件拖放到位。

You can also use the View - Other Windows - Document Outline window to make sure the panels are not inside each other. 您还可以使用“ View - Other Windows - Document Outline窗口确保面板不在彼此内部。

I guess the problem is because one panel sits on top of the other becoming a child of the other panel that's why you can't set it visible to true. 我想这个问题是因为一个面板位于另一个面板之上,成为另一个面板的孩子,这就是为什么你不能将它设置为true的原因。 To check that you can right click on your panel and if you have the option to select the other panel then it's clear that the panel has the other panel as his parent 要检查您是否可以右键单击面板,如果您可以选择其他面板,那么很明显该面板将另一个面板作为其父级

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

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