tags:

views:

37

answers:

2

I have an MDI form and several number of child forms inside that MDI. On clicking a button in the menu, a form opens. If another form is already open then that should get minimized and the new from should open. The problem is even if i give frm.WindowState=WindowState.Minimized, the form does not get minimized. The code that I have written is given below,

              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();                     
              }
+3  A: 

You're setting the WindowState of frmCS instead of f (the local variable in your for loop). Could that be the problem?

Dan Tao
I gave f.WindowState = FormWindowState.Minimized; inside the for loop. That did not work!!!
banupriya
I tried giving f.WindowState = FormWindowState.Minimized; and then f.Show(); then it worked out!!! The form got minimized!
banupriya
A: 

When an item in the menu is clicked, this code minimizes the currently active form and displays the new form.

          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();                     
          }
banupriya