Show/hide, BringToFront/SendToBack a panel on Parent form when a Child Form on the MDI Parent Form closes or appears

Deadly 提交于 2019-12-08 12:37:28

问题


I need to hide a panel on the Parent Form when a Child Form on an MDI Parent Form closes & show back the panel on the Parent form when the Child Form is closed.

Currently am using SendtoBack() to show the Child Form infront of the Panel which is on the Parent Form , but when i close the Child Form, then the Panel doesn't appears back, even if i use :

BringtoFront()

OR

Panel1.Visible=true


    public partial class CHILD : Form
        {
      private void CHILD_Load(object sender, EventArgs e)
            {
                this.FormClosed += new FormClosedEventHandler(CHILD_FormClosed);
            }

     void CHILD_FormClosed(object sender, FormClosedEventArgs e)
            {
                PARENTForm P = new PARENTForm();
                P.panel1.BringToFront();
                P.panel1.Visible = true; 

            }
}




public partial class Form1 : Form
   {
   private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                CHILD P = new CHILD();
                P.Showg();
                P.MdiParent = this;
                P.BringToFront();
                panel1.SendToBack();
                panel1.Visible = false;
            }
    }

THIS ISN'T WORKING....PLEASE HELP..!


回答1:


You creating new parent form in child form. You need to pass parent form object to child form and then use it to show/hide panel and set panel Modifiers property to public. For example...

Parent form:

public partial class ParentForm : Form
{
    public ParentForm()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        panel1.Visible = false;
        ChildForm childForm = new ChildForm();
        childForm.MdiParent = this;
        childForm.Show();
    }
}

Child form:

public partial class ChildForm : Form
{
    public ChildForm()
    {
        InitializeComponent();
    }

    private void Child_FormClosed(object sender, FormClosedEventArgs e)
    {
        ParentForm parentForm = (ParentForm)this.MdiParent;
        parentForm.panel1.Visible = true;
    }
}


来源:https://stackoverflow.com/questions/6040566/show-hide-bringtofront-sendtoback-a-panel-on-parent-form-when-a-child-form-on-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!