日期:2014-05-18  浏览次数:20968 次

新手学习:父窗体与子窗体
Frm_Main 的 IsMdiContainer已设置为true

添加了窗体one.cs、two.cs、three.cs

C# code

private void button1_Click(object sender,EventArgs e)
{
    one frmOne = new one();
    frmOne.MdiParent = this;
    frmOne.Show();
}

private void button2_Click(object sender, EventArgs e)
        {
            two frmTwo = new two();
            frmTwo.MdiParent = this;
            frmTwo.Show();
        }



点击button1会不断出现 子窗体one,一个又一个......,
点击button2会不断出现 子窗体two,一个又一个......,


如何写代码,使得,无论点击多少次button1,都只显示一个子窗体one

C# code
LayoutMdi(MdiLayout.TileVertical);


该写在哪里,才能实现,子窗体one与two 垂直平铺显示





------解决方案--------------------
探讨

把子窗体改造成单例模式

------解决方案--------------------
C# code

private void button1_Click(object sender,EventArgs e)
{
if(flag==true)
  {
  one frmOne = new one();
    frmOne.MdiParent = this;
    frmOne.Show();
   flag=false;
}
}