title: keeping the values of forms in c#
body: <p>I have two forms, form1 and form2. In form1, I have one label and two buttons. when I click on the button1, the result is shown in the label. Now, I click the second button and the form2 is loaded. in form2, I have one button and with clicking on it, form2 is closed and form1 is loaded. My question is here when form1 is loaded, the result does not exist in the label.
  how to keep the result in a special form when I go to another form and come back.</p>
  
  <p>The following code is for Form1 and second button</p>
  
  <pre><code> private void button2_Click(object sender, EventArgs e)
      {
          Form2 s = new Form2();
          s.Show();
          this.Hide();
      }
  </code></pre>
  
  <p>The following code is for Form2 and  button1</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
      {
          Form1 s = new Form1();
          s.Show();
          this.Hide();
      }
  </code></pre>
  
  <p>My problem was solved by the following code.</p>
  
  <pre><code> private void button2_Click(object sender, EventArgs e)
    {
     Form2 s = Application.OpenForms.OfType&lt;Form2&gt;().LastOrDefault();
          if (null == s)
          {
              s = new Form2();
              s.Show();
          }
          else
          {
              s.Activate();
              s.Visible = true;
          }
          this.Visible = false;
  }
  </code></pre>