I have a user control in my winforms application with this code in the KeyPress event:
private void txtCodigo_KeyPress(object sender, KeyPressEventArgs e)
{
if ((this.txtCodigo.Text.Length == 0) && (e.KeyChar == '\r'))
{
this.Limpiar();
if (LimpiarEvento != null)
LimpiarEvento(this, new EventArgs());
if (NextControl != null)
NextControl(this, new EventArgs());
}
if ((this.txtCodigo.Text.Length > 0) && (e.KeyChar == '\r'))
this.txtCodigo_Leave(sender, e);
if (NUMEROS.IndexOf(e.KeyChar) < 0)
{
e.Handled = true;
}
}
Now, my problem is that this UserControl is in many forms in my application and works perfectly when i press the enter key in the txtCodigo textbox but in one form the enter key is not being fired. Even if i put a breakpoint it doesn't fire at all. Why this could be happening?
Edit:
I just try to add a KeyPress
event to the form itself and set the KeyPreview
to true
and the Enter key is not being captured... all the other keys are being captured except the Enter key. I really don't know what is happening. And yes... the enter key works fine in the keyboard :)