title: Form closing save changes before close
body: <p>I have a Windows forms application in C# and I have a form that when the user closes it I ask, "do you want to save the changes"?  How can I get the changes in my form? Here is some code:</p>
  
  <pre><code>public partial class DepartEdit : Form
  {   
      string _nameDep; //This variavel get value textbox when form load
  
      {
          InitializeComponent();
      }
      private void DepartamentEdit_FormClosing(object sender, FormClosingEventArgs e)
      {
  
  
          if (txtNameDepart.Text != _nameDep &amp;&amp; codDepartament &gt; 0)//Here i compare
          {
              DialogResult dlg = MessageBox.Show("Save changes?", "Question", MessageBoxButtons.YesNo);
  
              if (dlg == DialogResult.Yes)
              {
                  saveDepart(); // Metod save depart
  
                  e.Cancel = false;
  
              }
              if(dlg ==DialogResult.No)
              {
                  e.Cancel = false;
  
              }
  
          }        
  }
  </code></pre>
  
  <p>There are a lot of textboxs and combo boxes? Is there any other way to get the changes in the form?</p>