title: Very strange bug when using Show Dialog on C# Winform
body: <p>I have created 2 forms in VS Studio 2008 Express Edition and declare them with public static in main program.cs file</p>
  
  <p>I just want to switch between the two forms with ShowDialog and Close but when trying to close the second form and open the first form again with showdialog it says I cannot use showDialog when the form is already visible, whereas it isn't true since I closed it before to show the second form.</p>
  
  <p>It asked me to set the form visible property to false before using showdialog, so I did it</p>
  
  <pre><code>    internal static void CloseSecondForm(FirstForm FirstForm)
      {
          FirstForm .Close();
          SecondForm.Visible = false;
          SecondForm.ShowDialog();
      }
  </code></pre>
  
  <p>But then it says I cannot use ShowDialog because the form is already shown in Dialog Mode and that I must close it. So I did what it asked</p>
  
  <pre><code>    internal static void CloseSecondForm(FirstForm FirstForm)
      {
          FirstForm .Close();
          SecondForm.Visible = false;
          SecondForm.Close();
          SecondForm.ShowDialog();
      }
  </code></pre>
  
  <p>But it still pretends that the form is already opened with ShowDialog !</p>
  
  <p>Is this a Bug in my prog or in Winform ?</p>
  
  <p>Update: this is the whole code I posted in 5th answer (I want to use showdialog and not show because I may have a 3rd form in Background that I don't want the user to access):</p>
  
  <pre><code>  [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Form1 = new Form1();
        Form2 = new Form2();
        Form1.ShowDialog();
        Application.Run();
  
    }
  
    // called from Form1 BUTTON
    internal static void ShowForm2(Form1 Form1)
    {
        Form1.Hide();
        Form2.ShowDialog();
    }
  
    // called from Form2 BUTTON
    internal static void ShowForm1(Form2 Form2)
    {
        Form2.Hide();
        Form1.ShowDialog();
    }
  </code></pre>
  
  <hr>
  
  <p>I tried with Hide as suggested but it doesn't work either. This is the whole program, what I want to do is very simple: I have two forms initially created in program with one button on each form to close self and open the other. I put all the logic in program.cs below:</p>
  
  <pre><code>  using System;
    using System.Windows.Forms;
  
    namespace twoforms
    {
        static class Program
        {
            /// &lt;summary&gt;
            /// The main entry point for the application.
            /// &lt;/summary&gt;
            /// 
            public static Form1 Form1;
            public static Form2 Form2;
  
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Form1 = new Form1();
                Form2 = new Form2();
                Form1.ShowDialog();
                Application.Run();
  
            }
  
            // called from Form1 BUTTON
            internal static void ShowForm2(Form1 Form1)
            {
                Form1.Hide();
                Form2.ShowDialog();
            }
  
            // called from Form2 BUTTON
            internal static void ShowForm1(Form2 Form2)
            {
                Form2.Hide();
                Form1.ShowDialog();
            }
        }
    }
  </code></pre>