title: Passing object to different windows forms
body: <p>I want to pass a C# object between win forms. At the moment, I have setup a basic project to learn how to do this which consists of two forms - form1 and form2 and a class called class1.cs which contains get and set methods to set a string variable with a value entered in form1. (Form 2 is supposed to get the value stored in the class1 object)</p>
  
  <p>How can I get the string value from the object that was set in form1? Do I need to pass it as a parameter to form2?</p>
  
  <p>Any comments/help will be appeciated!</p>
  
  <p>Thanks,</p>
  
  <p>EDIT: Here's the code I have at the moment: (form1.cs)</p>
  
  <pre><code>    private void button1_Click(object sender, EventArgs e)
      {
          this.Hide();
  
          Form2 form2 = new Form2();
  
          form2.Show();
      }
  
      private void button2_Click(object sender, EventArgs e)
      {
          if (textBox1.Text != "")
          {
              Class1 class1 = new Class1();
  
              class1.setStringValue(textBox1.Text);
          }
      }
  }
  </code></pre>
  
  <p>}</p>