title: c# Textchanged event fires twice in a multiline TextBox
body: <p>I have a very bizarre problem with the TextChanged event in a multiline TextBox (WinForms).
  it appears that the event fires twice under certain circumstances.</p>
  
  <p>This complete code demonstrates the issue:</p>
  
  <pre><code>public partial class TextChangedTest : Form
  {
      public TextChangedTest()
      {
          InitializeComponent();
      }
  
      private void TextChangedTest_Load(object sender, EventArgs e)
      {
          TextBox tb = new TextBox();
          //Remove the following line and the code behaves as expected
          tb.Multiline = true;
          this.Controls.Add(tb);
          tb.TextChanged += new EventHandler(tb_TextChanged);
      }
      private void tb_TextChanged(object sender,EventArgs e)
      {
          //Need to validate and use the new text here.
          //For testing, just use a MessageBox
          MessageBox.Show("Handler fired");
      }
  }
  </code></pre>
  
  <p>If you now type a character in the TextBox, the event fires. Correct behaviour.</p>
  
  <p>If you delete the character, the event fires once. Correct behaviour.</p>
  
  <p>If you delete the character with backspace, the event fires once. Correct behaviour.</p>
  
  <p>If you delete the character by selecting it and pressing Delete, the event fires once. Correct behaviour.</p>
  
  <p><strong>However</strong></p>
  
  <p>If you select the character and type another character, the event fires twice, once after the text box is cleared (look at the textbox when the first event fires) and once when the character is added. This behaviour is nonsense, if understandable.</p>
  
  <p>This only happens when the Multiline property is set (which I am using to resize the TextBox). It just took me 5 hours to work that out!</p>
  
  <p>My problem is that I have to validate each character in the TextChanged event, and I get invalid results.</p>
  
  <p>Does anyone have any ideas?</p>
  
  <p>I could possibly use the Keypress event, but I would need to do a lot of recoding to do that.</p>