title: Passing String to another forms from one form in c#
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9871958/how-to-pass-string-to-another-forms-from-one-form-in-c-sharp">How to Pass String to another forms from one form in c#</a>  </p>
  </blockquote>
  
  
  
  <p>C# Query : When I login to my software I select the desired username using combobox. After I login, I want to see the username text in the main window on the toolstrip.</p>
  
  <p>I tried get and set method but something is going wrong.  Can you please help me out? Thanks in advance.</p>
  
  <p>Form 1:</p>
  
  <pre><code>public partial class login : Form
  {
      public login()
      {
          InitializeComponent();
      }
  
      public string username
      {
          get{
              return a.ToString();}
      }
  
      public string a;
  
      private void button1_Click(object sender, EventArgs e)
      {
          a = comboBox1.Text;
          Form main1 = new main();
          main1.Show();
       // rest is the code for login.
      }
  }
  </code></pre>
  
  <p>Form 2:</p>
  
  <pre><code>public partial class main : Form
  {
      public main()
      {
          InitializeComponent();
      }
      public string username
      {
          set { toolStripLabel1.Text = value; }
      }
      private void main_Load(object sender, EventArgs e)
      {
          Form home = new home();
          home.MdiParent = this;
          home.WindowState = FormWindowState.Maximized;
          home.Show();
      }
  }
  </code></pre>
  
  <p>Here Home is form3 a childform which  opens in Main form. at load event of Main form itself.</p>