Pregunta

I'm trying to swipe a card and after the 5 characters are entered I want it to go to the next textfield. I'm scanning a card.

Currently I have:

private void membernumber1_TextChanged(object sender, EventArgs e)
    {
    }

But this changes it right after it enters one character, is there anyway to make it switch after 5 characters entered?

¿Fue útil?

Solución

Just count the number of characters in the Text property. Using a counter won't work if they use the backspace key.

if( membernumber1.Text.Length == 5 )
    SwitchFocus();

Be aware though that this may not work for text that was pasted into the control (i.e., if it was > 5 characters). You'll need proper validation for that case or you can just disable pasting, but validation is preferable as there are certainly other restrictions like being all numeric.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top