title: C++ - How do you pass a variable from one form to another?
body: <p>I have a Form1.h and a Form2.h</p>
  
  <p>Form1.h is already including Form2.h because i start Form2 by clicking a button in Form1. So how would i pass a variable from Form1.h to Form2.h</p>
  
  <p>Here is an example of Form1.h</p>
  
  <pre><code>#include "Form2.h"
  
  String^ str = "Hello World"; //This variable needs to be passed to Form2.h
  
  //Other windows forms application code here
  </code></pre>
  
  <p>An example of Form2.h</p>
  
  <pre><code>//#include "Form1.h" this will cause an error
  
  //How would i pass variable str to here?
  
  //Other windows forms application code here
  </code></pre>
  
  <p>Edit: </p>
  
  <p>This is how i fixed it</p>
  
  <p>This is how i fixed it.</p>
  
  <p>Form1.h</p>
  
  <pre><code>#include "Form1.h"
  
  Form2^ frm = gcnew Form2;
  frm-&gt;Username = "text here";//This passes the variables.
  frm-&gt;Password = "other text";
  </code></pre>
  
  <p>Form2.h</p>
  
  <pre><code>public: String^ Username;
  public: String^ Password;
  </code></pre>