title: Closing form and capture closing event
body: <p>everyone.
  I've run into such a problem. In my app, I show second form from my main form through ShowDialog method. In this form I have some textBox(s) to connect to the DB and a Connect button. If user clicks X, the app exit. But if user click "connect" - I connect to DB and also close my second form. To catch closing event I use FormClosing method where the app asks whether I'm about to close the app and if yes it exit. The problem is that when I click the button, FormClosing event fires and asks me if I want to exit. How to avoid it? I try to use sender, but it doesn't work.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>private void Connect_Click(object sender, EventArgs e)
  {
      try
      {
           orcl.connect(userID.Text, Password.Text, comboTNS.Text);
  
           if (orcl.ifHasRows("select dbclass from setupdbversion where dbclass='SECURITY' and rownum=1"))
           {//my stuff
               this.Close();
           }
  
       }
       catch (Exception ex)
       {
            MessageBox.Show(ex.Message.ToString());
       };
  }
  
  
  private void SecConnForm_FormClosing_1(object sender, FormClosingEventArgs e)
  {   
       MessageBox.Show(sender.ToString());
       if (e.CloseReason == CloseReason.UserClosing)
       {
            MessageBox.Show(sender.ToString());
            if (string.Equals((sender as Form).Name, @"SecConnForm")) //it doesn't work as in any cases the sender is my form, not a button (when i click on button of course)
            {
                 if (MessageBox.Show(this, "Really exit?", "Closing...",
                      MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
                         == DialogResult.Cancel) 
                     e.Cancel = true;
                 else
                     Application.Exit();
  
            }
            else
            {
                 //other stuff goes..
            }
       }
  }
  </code></pre>