且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当MDI父窗体上的子窗体关闭或出现时,在父窗体上显示/隐藏,BringToFront/SendToBack面板

更新时间:2023-12-06 09:01:22

您将在子表单中创建新的父表单.您需要将父表单对象传递给子表单,然后使用它显示/隐藏面板并将面板的Modifiers属性设置为public. 例如...

父母表格:

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();
    }
}

子窗体:

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

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..!

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