C#MDI中防止子窗体被多次实例化

第一种方式:

代码
if (gongChenJinDuFrm == null || gongChenJinDuFrm.IsDisposed)
{
gongChenJinDuFrm
= new GongChenJinDuFrm();
}
gongChenJinDuFrm.Text
= "工程进度--" + DGJName;
gongChenJinDuFrm.FillData(DGJID);
gongChenJinDuFrm.MdiParent
= this;
gongChenJinDuFrm.WindowState
= FormWindowState.Normal;
gongChenJinDuFrm.MaximizeBox
= false;
gongChenJinDuFrm.StartPosition
= FormStartPosition.CenterScreen;
gongChenJinDuFrm.Show();

 

第二种方式:

 

代码
private static GongChenJinDuFrm gongChenJinDuFrm;
private GongChenJinDuFrm GetGongChenJinDuFrm()
{
//先后次序不能错,前一个条件用来判断是否是第一次,后一个条件用来判断子窗体是否被关闭了
if (gongChenJinDuFrm == null || gongChenJinDuFrm.IsDisposed)
{
//第一次实例化也好,被关了也好,都重新实例化
gongChenJinDuFrm = new GongChenJinDuFrm();
gongChenJinDuFrm.MdiParent
= this;
}
return gongChenJinDuFrm;
}

 

posted @ 2010-10-16 22:44  周超亿  阅读(335)  评论(0编辑  收藏  举报