簡體   English   中英

如何從另一個Mdi子表單中顯示(Bringtofront)已經打開的Mdi子表單?

[英]How to show(Bringtofront) an already opened Mdi child form from another Mdi child form?

在我的應用程序中,我有4個表單,form1是一個mdi容器,其余表單是它的子容器,在form1中,我正在其load事件中打開所有子表單。 在子form2中,我有一個將切換到childform3的按鈕。我的問題是如何從childform2中的按鈕顯示childform3(已打開)

               form1:

               Form2 formchild1;
               Form3 formchild2;
               Form4 formchild3;

        private void Form1_Load(object sender, EventArgs e)
        {


        if (formchild2 == null)
        {
            formchild2 = new Form3();
        }
        formchild2.MdiParent = this;
        formchild2.Dock = DockStyle.Fill;
        formchild2.Show();
        //formchild2.BringToFront();


        if (formchild3 == null)
        {
            formchild3 = new Form4();
        }
        formchild3.MdiParent = this;
        formchild3.Dock = DockStyle.Fill;
        formchild3.Show();


        if (formchild1 == null)
        {
            formchild1 = new Form2();
        }
        formchild1.MdiParent = this;
        formchild1.Show();
        formchild1.Dock = DockStyle.Fill;
        formchild1.BringToFront();


        }


        form2:

        Form3 formchild2;
   private void button1_Click(object sender, EventArgs e)
    {
        //what i have to write hare..
            //formchild2 = new Form3();
            //formchild2.MdiParent = this.ParentForm;

            //formchild2.Dock = DockStyle.Fill;
            //formchild2.Show();
            //formchild2.BringToFront();

    }

創建form2時(請更改變量名,花了一段時間才發現formchild1實際上是form2),您需要實例化form2實例。

if (formchild1 == null)
{
    formchild1 = new Form2(/*Either pass in a Form3 here*/);
}
formchild1.formChild2 = formchild2; //Or make formChild2 public member
formchlid1.SetForm(formChild2); //Or make a method that sets it
formchild1.MdiParent = this;
formchild1.Show();
formchild1.Dock = DockStyle.Fill;
formchild1.BringToFront();

然后再次顯示它,你可以做

formchild2.BringToFront();
childform3 childform3=new childform3;

private void button1_Click(object sender, EventArgs e)
    {
        if (!childform3.IsDisposed)
            childform3.Select();
        else
            childform3= new frmSearch();
        childform3.MdiParent = ParentForm;
        childform3.Show();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM