title: How can I get the main form of a .NET 4 application to come to the front?
body: <p>I have an .NET 4 WinForm application.  I have a button on the main form that opens a child form.  The child form has focus.  While the child form is open, if I click on the main form, the main form receives focus, but the child form remains on top of the main form.  </p>
  
  <p>How can I make the main form come to the front, even if the child form is open?</p>
  
  <p>Here is my sample code for the two forms:</p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  
  namespace WinTest
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              var form = new Form2();
  
              form.Show(this);
          }
      }
  }
  
  using System.Windows.Forms;
  
  namespace WinTest
  {
      public partial class Form2 : Form
      {
          public Form2()
          {
              InitializeComponent();
          }
      }
  }
  </code></pre>
  
  <p>Based on Kumar's answer below, I updated my main form as follows:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Windows.Forms;
  
  namespace WinTest
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
  
              _FormList = new List&lt;Form&gt;();
          }
  
          private List&lt;Form&gt; _FormList;
  
          private void button1_Click(object sender, EventArgs e)
          {
              var form = new Form2();
              form.FormClosed += Form_FormClosed;
              _FormList.Add(form);
              form.Show();
          }
  
          private void Form_FormClosed(object sender, FormClosedEventArgs e)
          {
              _FormList.Remove((Form)sender);
          }
  
          private void Form1_Resize(object sender, EventArgs e)
          {
              foreach (var form in _FormList)
              {
                  form.Visible = WindowState != FormWindowState.Minimized;
              }
          }
      }
  }
  </code></pre>
  
  <p>This now works as expected.</p>