title: How To Open The Previous Form And Close The Current In C#?
body: <p>I am working on a desktop app building on Windows Forms in C# on Visual Studio 2015 where I have too many forms that are attached among them using the below codes.</p>
  
  <p><strong>First Form:</strong></p>
  
  <pre><code>using System;
  namespace MyApps
  {
      public partial class MainForm : Form
      {
          public MainForm()
          {
              InitializeComponent();
          }
          private void btnForward_Click(object sender, EventArgs e)
          {
              SecondForm openForm= new SecondForm();
              openForm.Show();
              this.Hide();
          }  
      }
  }
  </code></pre>
  
  <p><strong>Second Form:</strong></p>
  
  <pre><code>using System;
  namespace MyApps
  {
      public partial class SecondForm: Form
      {
          public SecondForm()
          {
              InitializeComponent();
          }
          private void btnBack_Click(object sender, EventArgs e)
          {
              // +++++++++++ Need To Write The UPDATED Code Here +++++++++++
              MainForm openForm= new MainForm();
              openForm.Show();
              this.Hide();
          } 
      }
  }
  </code></pre>
  
  <p><strong>Third Form:</strong></p>
  
  <pre><code>using System;
  namespace MyApps
  {
      public partial class ThirdForm: Form
      {
          public ThirdForm()
          {
              InitializeComponent();
          }
          private void btnForward_Click(object sender, EventArgs e)
          {
              SecondForm openForm= new SecondForm();
              openForm.Show();
              this.Hide();
          }  
      }
  }
  </code></pre>
  
  <p>So I am ok with the code to open the new form but I want the code to go back that should be general means if I open the <code>SecondForm</code> from <code>MainForm</code> then on clicking its back button, I should be on <code>MainForm</code> but if I open it from any other form like <code>ThirdForm</code> then on clicking the same button on <code>SecondForm</code>, I should be on <code>ThirdForm</code> so what code should I use on <code>SecondForm</code> back button?</p>