title: TextBox not listening Enter key before Space key is pressed in C#
body: <p>I have to process an "Enter" key event on text box so I created a new class inheriting from textBox and have already overridden the IsInputKey method. Problem is the KeyDown event is not being fired with out pressing the space bar first.</p>
  
  <pre><code>public class EnterTextBox : TextBox
  {
      protected override bool IsInputKey(Keys keyData)
      {
          if (keyData == Keys.Enter)
          {
              return true;
          }
          else
          {
              return base.IsInputKey(keyData);
          }
      }
  }
  </code></pre>
  
  <p>After creating from the above class as</p>
  
  <pre><code>EnterLisTextBox enterTextBox1 = new EnterLisTextBox();            
  enterTextBox1.KeyDown += enterTextBox1_KeyDown;
  </code></pre>
  
  <p>the key down event handler is </p>
  
  <pre><code>void enterTextBox1_KeyDown(object sender, KeyEventArgs e)
  {
      if (e.KeyCode == Keys.Enter)
      {
          MessageBox.Show("Pressed enter");;
      }  
  }
  </code></pre>
  
  <p>But this only works if I pressed the "Space bar" before using the "Enter key". But once i pressed the space bar even if I retype every thing on the text box it works. Why is this? Why is it the prerequisite to press the space bar? </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Implementing keyPress event worked for me, but if any one has any idea why the above not worked before using the sapce bar. This is the how i used keypress, note the <strong><em>e.KeyChar == '\r'</em></strong></p>
  
  <pre><code>void enterTextBox1_KeyPress(object sender, KeyPressEventArgs e)
  {
      if (e.KeyChar == '\r')
      {
          MessageBox.Show("Pressed enter");
      }  
  }
  </code></pre>