首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

子窗体不重复解决办法

2012-01-02 
子窗体不重复privatestaticForm1f1privateForm1getf1(){if(f1null||f1.IsDisposed){f1newForm1()f1.M

子窗体不重复
private   static   Form1   f1;
                private   Form1   getf1()
                {
                        if   (f1   ==   null   ||   f1.IsDisposed)
                        {
                                f1   =   new   Form1();
                                f1.MdiParent=this;
                        }
                        return   f1;
                }
                private   void   toolStripButton1_Click(object   sender,   EventArgs   e)
                {
                        Form1   f1   =   getf1();
                        f1.Show();
                        f1.Focus();
                }

[解决办法]
用进程锁
bool create;
Mutex m=new Mutex(true, "text ",out create);
if(create)
{
Application.Run(new Form1());
m.ReleaseMutex();
}
这段代码加到子窗体的构造函数中

热点排行