title: Disposing a form from parent form in C#?
body: <p>I have a form which will open a new form when one button (form1button) is clicked. And on the child form there will be another button 'form2button'. Now if I click this form2button the new form2 should be disposed. But because the form2 object is created here in form1 class method, I cannot dispose that object in form2 class method (fom2buttonclick). So I used static to get my work done as in the following psuedo code.</p>
  
  <p>Form1:
  <p></p>
  
  <pre><code>class Form1 : Form
  {
      static Form2 f2;
  
      public void Form1_buttonclick(object sender, EventArgs e)
      {
          f2 = new Form2();
      }
  
      public void Disposef2()
      {
          f2.Dispose();
      }
  }
  </code></pre>
  
  <p>Form2:</p>
  
  <pre><code>class Form2 : Form
  {
      public void Form2_buttonclick(object sender, EventArgs e)
      {
          Form1 f1 = new Form1();
          f1.Disposef2();
      }
  }
  </code></pre>
  
  <p>Is there any other better way to do it. Or C# design itself doesnot provide an alternative mechanism. I am new to C#.Please help me out..</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I want to close (dispose explicitely) form2 object which is created in form1 class when button on form2 is clicked. This edit is to give some more clarity.</p>