title: Access Of Public Method Between Forms
body: <p>I am trying to get access to Form1’s public method on another form Form2 as below. I have a <code>textbox6</code> control on form1 and there is public method to bind it. But I want to bind it by form2 as below. </p>
  
  <p><strong>Form1</strong></p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          Form2 f2 = new Form2();
          f2.Show();
      }
  
      public void amount_sum()
      {
          string connstr = " server=.;initial catalog=maa;uid=mah;pwd=mah";
          SqlConnection con = new SqlConnection(connstr);
          con.Open();
          string sql = " select sum(amount)as amount from method";
          SqlDataAdapter dap = new SqlDataAdapter(sql, con);
          DataSet ds = new DataSet();
          dap.Fill(ds);
          for (int i = 0; i &lt; ds.Tables[0].Rows.Count; i++)
          {
              textBox6.Text = Convert.ToString(ds.Tables[0].Rows[i]["amount"]);
          }    
      }
  }
  </code></pre>
  
  <p><strong>Form2</strong></p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      Form1 f1 = new Form1();
      f1.amount_sum();
      this.Close();
  }
  </code></pre>
  
  <p>The above method-call is wrong. Please suggest how to correct it.</p>
  
  <p>I want to bind Form1’s <code>textBox6</code> control from Form2's <code>Button_Click</code> event-handler by calling the public method, and when Form2 is closed, then Form1’s <code>textbox6</code> should be bound. Is that possible by calling the public method from Form2?</p>