title: Why (sender as "something") have null value in c# windows forms app
body: <p>I'm trying to write an form_close event in C# windows forms app that will do different things depending on what control launched application close.</p>
  
  <p>I have </p>
  
  <pre><code>    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
      {
          Close();
      }
  </code></pre>
  
  <p>to close application from main menu, and </p>
  
  <pre><code>    private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
      {
          if ((sender as ToolStripMenuItem).Name == @"exitToolStripMenuItem")
          { }
  }
  </code></pre>
  
  <p>to process form_closing, and show different message depending on control.</p>
  
  <p>Problem is, that value of "<code>sender as toolstripmenuitem</code>" is always null, and exception is thrown.</p>
  
  <p>Can someone help me to fix this?</p>