Good morning, Currently I have an application in which you can enter a text in a textbox. There is also a timer every 750 ms that verifies that this text measures more than 12 characters and executes a procedure. When you finish executing the procedure that is in the timer, you should leave the textbox empty. However, this does not always happen, and sometimes the textbox appears filled. I tried the following but it did not work for me, I would appreciate someone giving me some clue how to fix it.
private void tmCompruebaCodigo_Tick(object sender, EventArgs e)
{
this.txtCodigo.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtCodigo_KeyDown);
this.txtCodigo.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtCodigo_KeyPress);
if (txtCodigo.Text.Length >= 13 && txtCodigo.Text != codigoAnterior)
{
inicia();
txtCodigo.Text = "";
txtCodigo.Focus();
}
this.txtCodigo.KeyDown -= new System.Windows.Forms.KeyEventHandler(this.txtCodigo_KeyDown);
this.txtCodigo.KeyPress -= new System.Windows.Forms.KeyPressEventHandler(this.txtCodigo_KeyPress);
}
private void txtCodigo_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
e.Handled = true;
}
private void txtCodigo_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}