title: Winforms C# pass variable between forms
body: <p>How do i pass <code>name</code> value from Form1 to Form2?</p>
  <blockquote>
  <p>Form1</p>
  </blockquote>
  <pre><code>public partial class Form1 : Form
  {
      public string name = &quot;xxx&quot;;
  }
  </code></pre>
  <blockquote>
  <p>Form2</p>
  </blockquote>
  <pre><code>public partial class Form2 : Form
  {
      private void Form2_Load(object sender, EventArgs e)
      {
          lblname.Text = name;
      }
  }
  </code></pre>
  <hr />
  <h1>Solution:</h1>
  <blockquote>
  <p>Form1</p>
  </blockquote>
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          string name = &quot;xxx&quot;;
          Form2 frm2 = new Form2(name);
          frm2.Show();
      }
  }
  </code></pre>
  <blockquote>
  <p>Form2</p>
  </blockquote>
  <pre><code>public partial class Form2 : Form
  {
      public Form2(string name)
      {
          InitializeComponent();
          label1.Text = name;
      }
  }
  </code></pre>