MDI Child表单没有最小化

时间:2010-09-14 12:13:44

标签: c# .net winforms

我在MDI中有一个MDI表单和几个子表单。单击菜单中的按钮,将打开一个表单。如果另一个表单已经打开,那么应该最小化并且应该打开new。问题是即使我给frm.WindowState = WindowState.Minimized,表单也不会被最小化。我写的代码如下:

              frmReaserchData childForm = null;
              foreach (Form f in this.MdiChildren)
              {
                  if (f is frmReaserchData)
                  {
                      // found it 
                      childForm = (frmReaserchData)f;
                      break;
                  }
                  else
                  {                                                   
                        f.WindowState = FormWindowState.Minimized;                           
                  }

              }

              if (childForm != null)
              {                    
                  childForm.Focus();
              }
              else
              {
                  childForm = new frmReaserchData();
                  childForm.MdiParent = this;
                  childForm.Show();                     
              }

2 个答案:

答案 0 :(得分:3)

您设置WindowState的{​​{1}}而不是frmCSf循环中的局部变量)。这可能是问题吗?

答案 1 :(得分:0)

单击菜单中的项目时,此代码会最小化当前活动的表单并显示新表单。

          frmReaserchData childForm = null;
          foreach (Form f in this.MdiChildren)
          {
              if (f is frmReaserchData)
              {
                  // found it 
                  childForm = (frmReaserchData)f;
                  break;
              }
              else
              {                                                   
                    f.WindowState = FormWindowState.Minimized; 
                    f.Show();                          
              }

          }

          if (childForm != null)
          {                    
              childForm.Focus();
          }
          else
          {
              childForm = new frmReaserchData();
              childForm.MdiParent = this;
              childForm.Show();                     
          }