title: C# - Pushing Enter in MessageBox triggers control KeyUp Event
body: <p>System: Windows7 Pro, Visual Studio 2010, C#</p>
  
  <p>I have a textbox: <code>textBox1</code>
  I set its event:</p>
  
  <pre><code>textBox1.KeyUp += new KeyEventHandler(textBox1_KeyUp);
  
  private void textBox1_KeyUp(object sender, KeyEventArgs e)
  {
      if (e.KeyCode == Keys.Enter)
      {
          button1.PerformClick();
      }
  }
  
  private void button1_Click(object sender, EventArgs e)
  { 
      if (string.IsNullOrEmpty(textBox1.Text))
      {
          MessageBox.Show("Invalid data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
      } 
  }
  </code></pre>
  
  <p>It works fine, the problem is, when the data entered is invalid, and thus the <code>MessageBox</code> is shown, when i hit <kbd>ENTER</kbd> on the <code>MessageBox</code> OK Button, it also triggers the <code>textBox1_KeyUp</code>, which causes the <code>MessageBox</code> to show up again.
  So, it triggers the <code>MessageBox</code> OK button, which causes it to disappear, and also triggers the <code>textbox_keyUp</code> which then causes the messagebox to show up again. </p>
  
  <p>Thanks for your help.</p>