priavte UsForm sForm=null;按钮代码
if (sForm != null)
            {
                sForm.Show();
                sForm.Focus();
            }
            else
            {                
                sForm = new UsForm();
                sForm.MdiParent = this;
                sForm.Show();                
                sForm.Focus();
            }    
解释一下。UsForm,是我调用的CS.dll文件下的。现在是我在MDI窗体Main下一个按钮里调用的,现在是不会同时打开二个实例,可我关闭实例,再次运行,就没有任何反映,请帮忙啊

解决方案 »

  1.   

    我把代码改成
     if (MUpPassForm == null)
                {
                    ShowUpPassForm();
                }
                else
                {
                    if (MUpPassForm.Text.ToString().Trim() == "")
                    {
                        ShowUpPassForm();
                    }
                }   
    private void ShowUpPassForm()
            {
                MUpPassForm = new UpPassForm();
                MUpPassForm.MdiParent = this;
                MUpPassForm.Show();
                MUpPassForm.Focus(); 
            }
    就可以了,哪这样的话,也没得啥子意思啊,为什么  MUpPassForm !=null      我直接让他show会有错误啊
      

  2.   

    可能sForm虽被销毁,但没有置为null.
      

  3.   

    priavte UsForm sForm=null;按钮代码
    if (!sForm.Visible)
                {
                    sForm.Focus();
                }
                else
                {                
                    sForm = new UsForm();
                    sForm.MdiParent = this;
                    sForm.Show();                
                    sForm.Focus();
                }    
      

  4.   

    >>sForm虽被销毁,但没有置为null
      

  5.   

    UsForm sForm = null;
    foreach(Form f in this.MdiChildren)
    {
    if(f is UsForm)
    {
    sForm = (UsForm)f;
    break;
    }
    }
    if(sForm != null)
    {
    sForm.Show();
    sForm.Focus();
    }
    else
    {
    sForm = new UsForm();
    sForm.MdiParent = this;
    sForm.Show();
    sForm.Focus();
    }
    试试这样
      

  6.   

    我的代码就是上面的代码,我的想法是MUpPassForm 虽然关闭,但并没有赋值为null,所以我才有正判断他的text文本
      

  7.   

    我完全照MyChildForm childForm = null; 
     
         foreach(Form f in this.MdiChildren) 
     
         { 
     
              if(f is MyChildForm) 
     
              { 
     
                   // found it 
     
                   childForm = (MyChildForm) f; 
     
                   break; 
     
              } 
     
         } 
      
         if( childForm != null) 
     
         { 
     
              childForm.Show(); 
     
              childForm.Focus(); 
     
         } 
     
         else 
     
         { 
     
              childForm = new MyChildForm(); 
     
              childForm.MdiParent = this; 
     
              childForm.Show(); 
     
              childForm.Focus(); 
     
         }
    这个简单的修改了一下我的窗体名而已反正第二次打开后就没有任何显示
     
      

  8.   

    UsForm sForm = null;//这块不是已经赋为null
    以后的代码是查询当前的MdiChildren集中,如果没有的话,当然也不会修改其值
      

  9.   

    我在程序开始加了句UsForm sForm = null;的啊设为的是private
      

  10.   

    如果你是调用cs.dll来生成你的mdichild的话,那你就应该修改你的cs.dll中相应子窗体类的close方法,从而在调用此类对象close方法时,能进行消除对象,这样就不会出现你上面所说的现象。
      

  11.   

    to 我在程序开始加了句UsForm sForm = null;的啊设为的是private
    不要设为全局的,定义为函数的局部变量
      

  12.   

    对,大哥,我就是调用cs.dll来生成mdichild的,可在cs.dll的窗体里面的close怎么写啊,怎么清除啊
      

  13.   

    给我看看你怎么定义你的mdichild类的
      

  14.   

    大哥,我cs.dll下我只做了一个窗体文件啊,什么也没有,就是为了演示一下看行不行,我把这个编译的一个dll文件,我在另外的项目中调用啊,我调用的代码就是
    foreach(Form f in this.MdiChildren)
    {
    if(f is UsForm)
    {
    sForm = (UsForm)f;
    break;
    }
    }if (sForm != null)
                {
                    sForm.Show();
                    sForm.Focus();
                }
                else
                {                
                    sForm = new UsForm();
                    sForm.MdiParent = this;
                    sForm.Show();                
                    sForm.Focus();
                }    
      

  15.   

    至于你说的UsForm sForm = null;我也在程序开始的时候加了的,其余我就没有任何代码了
      

  16.   

    不要设为全局的,定义为函数的局部变量把
    private UsForm sForm = null;
    删除,然后在你进行判断的时候,
    在函数内部加上
    UsForm sForm = null;例如:
    //Add a document
    private void AddDocument() 
    {
    // MyChildForm is the one I'm looking for 
     
    Document childForm = null; 
    foreach(Form f in this.MdiChildren) 

    if(f is Document) 

    // found it 
    childForm = (Document) f; 
    break; 


     
    if( childForm != null) 

    childForm.Show(); 
    childForm.Focus(); 

    else 

    childForm = new Document("Document "); 
    childForm.MdiParent = this; 
    childForm.Show(); 
    childForm.Focus(); 
    }
      }
      

  17.   

    可以了,高手就是高手啊,我哪天给专门得向你拜师,我是十分十分十分的感谢
    另,大哥,foreach(Form f in this.MdiChildren) 

    if(f is Document) 

    // found it 
    childForm = (Document) f; 
    break; 


    这些代码,我感觉没什么用嘛,也就是找到他也没有什么有用的吧
      

  18.   

    大哥,加下QQ嘛,以后有问题,希望能请教你一下,OK?
      

  19.   

    sorry!
    我不用QQ,如果有什么问题的话,发邮件给我 [email protected]